home *** CD-ROM | disk | FTP | other *** search
-
- /******************************************************************************
- * *
- * NTrash Version 1.1 - File Deletion utility for Windows NT *
- * *
- * by Mark Gamber - August 3, 1992 *
- * *
- * Compiled for July 1992 WinNT release. *
- * *
- ******************************************************************************/
-
-
- #include "windows.h"
- #include "ntrash11.h"
-
-
- HANDLE hInst; // Global Variables go here
- HWND MainWin;
- BOOL StayOnTop = TRUE;
- char *IniSection = "NTRASH";
- char *IniFile = "NTRASH.INI";
-
-
- int PASCAL WinMain( HANDLE hInstance, HANDLE hPrev, LPSTR lpCmd, int nCmdShow )
- {
- WNDCLASS wc;
- HWND hWnd;
- MSG msg;
- UINT Xpos, Ypos;
-
- if( hPrev )
- return( FALSE );
-
- wc.style = CS_DBLCLKS; // Accept double-clicks
- wc.lpfnWndProc = MainWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon( hInstance, "MainI" );
- wc.hCursor = LoadCursor( NULL, IDC_ARROW );
- wc.hbrBackground = GetStockObject( LTGRAY_BRUSH );
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "CTEST";
-
- if( ! RegisterClass( &wc ) ) // If class doesn't register, exit
- return( FALSE );
-
- hInst = hInstance;
-
- Xpos = GetPrivateProfileInt( IniSection, "XPOS", 0, IniFile );
- Ypos = GetPrivateProfileInt( IniSection, "YPOS", 0, IniFile );
- StayOnTop = GetPrivateProfileInt( IniSection, "SOT", 1, IniFile );
-
- hWnd = CreateWindowEx( WS_EX_ACCEPTFILES | WS_EX_TOPMOST,
- "CTEST",
- (LPSTR)"Test",
- WS_VISIBLE | WS_CLIPSIBLINGS | WS_POPUP,
- Xpos, Ypos,
- 48, 48,
- NULL,
- NULL,
- hInstance,
- NULL );
-
- if( ! hWnd )
- return( FALSE ); // If create failed, exit program
-
- MainWin = hWnd;
- ShowWindow( hWnd, SW_SHOWNORMAL ); // Display window
- UpdateWindow( hWnd );
-
- if( StayOnTop )
- SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
- else
- SetWindowPos( hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
-
- while( GetMessage( &msg, NULL, NULL, NULL ) ) // Do message loop
- {
- TranslateMessage( &msg ); // This is hauntingly familiar, no?
- DispatchMessage( &msg );
- }
- return( msg.wParam );
- }
-
-
-
- // Main window - This is the one that accepts files...
-
- long APIENTRY MainWndProc( HWND hWnd, UINT msg, UINT wParam, LONG lParam )
- {
- switch( msg )
- {
- case WM_LBUTTONDOWN: // If left button pressed, move window
- {
- PostMessage( hWnd, WM_SYSCOMMAND, 0xF012, 0x00110017 );
- break;
- }
-
- case WM_RBUTTONDOWN: // If right button pressed...
- { // Note - no more of this MakeProcInstance nonsense
- DialogBox( hInst, "MAINDLG", hWnd, MainDlgProc );
- break;
- }
-
- case WM_LBUTTONDBLCLK: // Quit on double-click
- {
- RECT Rect;
- char str[ 8 ];
-
- GetWindowRect( hWnd, &Rect );
- wsprintf( str, "%d", Rect.left );
- WritePrivateProfileString( IniSection, "XPOS", str, IniFile );
- wsprintf( str, "%d", Rect.top );
- WritePrivateProfileString( IniSection, "YPOS", str, IniFile );
- wsprintf( str, "%d", StayOnTop );
- WritePrivateProfileString( IniSection, "SOT", str, IniFile );
- PostQuitMessage( 0 );
- break;
- }
-
- case WM_DROPFILES: // When files are dropped on the window...
- {
- WORD Files, Count, len;
- char Filename[ 128 ];
- char FullPath[ 192 ];
- char TempPath[ 64 ];
- HDC hDC;
- HDC mDC;
- HBITMAP hBmp;
- // Get number of files dropped
- Files = DragQueryFile( wParam, -1, Filename, 128 );
- if( ! Files )
- {
- DragFinish( wParam ); // If none, tell SHELL and exit
- return( TRUE );
- } // Search for a TMP variable
-
- if( ! GetEnvironmentVariable( "tmp", TempPath, 64 ) )
- {
- MessageBox( hWnd, "TMP system variable is not set!\n Unable to Continue",
- "Error", MB_OK | MB_ICONSTOP );
- DragFinish( wParam );
- return( TRUE ); // If no TMP, tell user and exit
- }
-
- hDC = GetDC( hWnd );
- mDC = CreateCompatibleDC( hDC ); // Draw can with the lid up
- hBmp = LoadBitmap( hInst, "TUP" );
- SelectObject( mDC, hBmp );
- BitBlt( hDC, 0, 0, 48, 48, mDC, 0, 0, SRCCOPY );
- DeleteDC( mDC );
- DeleteObject( hBmp );
- ReleaseDC( hWnd, hDC );
-
- for( Count = 0; Count < Files; Count++ ) // Get every file dropped
- {
- DragQueryFile( wParam, Count, Filename, 128 );
-
- lstrcpy( FullPath, TempPath ); // Begin dest. path
- lstrcat( FullPath, "\\" ); // Add backslash
-
- len = lstrlen( Filename ); // Get length of filename passed
- while( Filename[ len ] != '\\' ) // Search for first backslash
- --len; // i.e. Find start of filename
-
- lstrcat( FullPath, Filename + len + 1 ); // Add filename to path
- CopyFile( Filename, FullPath, FALSE ); // Copy to destination
- DeleteFile( Filename );
- }
- DragFinish( wParam ); // Tell SHELL we're done
- InvalidateRect( hWnd, NULL, FALSE ); // Repaint with lid down
- return( TRUE );
- }
-
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hDC;
- HDC mDC;
- HBITMAP hBmp;
-
- hDC = BeginPaint( hWnd, &ps ); // Blasts out can with lid down
- mDC = CreateCompatibleDC( hDC );
- hBmp = LoadBitmap( hInst, "TDOWN" );
- SelectObject( mDC, hBmp );
- BitBlt( hDC, 0, 0, 48, 48, mDC, 0, 0, SRCCOPY );
- DeleteDC( mDC );
- DeleteObject( hBmp );
- EndPaint( hWnd, &ps );
- break;
- }
-
- case WM_DESTROY:
- PostQuitMessage( 0 );
- break;
-
- default:
- return( DefWindowProc( hWnd, msg, wParam, lParam ) );
- }
- return( FALSE );
- }
-
-
- // Settings dialog box....and purges TMP directory
-
- BOOL APIENTRY MainDlgProc( HWND hDlg, UINT msg, UINT wParam, LONG lParam )
- {
- switch( msg )
- {
- case WM_INITDIALOG: // Set checkbox
- CheckDlgButton( hDlg, IDM_STAYONTOP, StayOnTop );
- return( TRUE );
-
- case WM_COMMAND:
- if( wParam == IDCANCEL ) // When Exit it pressed...
- { // Save 'Stay On Top' setting
- StayOnTop = IsDlgButtonChecked( hDlg, IDM_STAYONTOP );
-
- // If checked, mark window accordingly
- if( StayOnTop )
- SetWindowPos( GetParent( hDlg ), HWND_TOPMOST, 0, 0, 0, 0,
- SWP_NOMOVE | SWP_NOSIZE );
- else
- SetWindowPos( GetParent( hDlg ), HWND_NOTOPMOST, 0, 0, 0, 0,
- SWP_NOMOVE | SWP_NOSIZE );
-
- EndDialog( hDlg, TRUE );
- return( TRUE );
- }
- if( wParam == IDM_PURGE )
- {
- int Status;
- char TempPath[ 128 ];
-
- Status = MessageBox( hDlg, "Actually delete all files?",
- "Trash Can", MB_YESNO | MB_ICONEXCLAMATION );
- if( Status == IDNO )
- break;
- if( ! GetEnvironmentVariable( "tmp", TempPath, 128 ) )
- break;
-
- lstrcat( TempPath, "\\*.*" );
- DeleteFile( TempPath );
- break;
- }
- break;
- }
- return( FALSE );
- }
-