/* ------------------------------------------------------- Dave Jewell's Quick Start (EXE magazine July 1996) Implemented in VC++ by John Cant PHD Computer Consultants Ltd 27 Rippingham Road, Withington, Manchester M20 3FX, United Kingdom Tel: (+44) 161 445 1650 Fax: (+44) 161 445 4707 Email: good-tech@mcr1.poptel.org.uk Web: http://www.poptel.org.uk/phdcc --------------------------------------------------------*/ #include #include "resource.h" static char appName[] = "QuickStart"; HANDLE hI; char dtfBuf[MAX_PATH - 1]; unsigned long dtfBufLen = MAX_PATH - 1; NOTIFYICONDATA nid; char* commands[255]; int cmdCount = 0; long FAR PASCAL WndProc( HWND, UINT, UINT, LONG); void Panic( char* panicMsg) { if (panicMsg == NULL || strlen( panicMsg) == 0) MessageBox( 0, "Illegal Panic!", appName, MB_OK); else MessageBox( 0, panicMsg, appName, MB_OK); } void AddCommand( HMENU hMenu, char* folder, char* fileName) { char buf1[MAX_PATH-1]; //build the full pathname strcat( strcpy( buf1, folder), fileName); commands[cmdCount] = new char[strlen( buf1) + 1]; strcpy( commands[cmdCount], buf1); // clean up command name for menu char* ptr; if( ptr = strrchr( fileName, '.')) { if( _stricmp( ptr, ".LNK") == 0) *ptr = 0; if( _stricmp( ptr, ".PIF") == 0) *ptr = 0; } AppendMenu( hMenu, MF_STRING, cmdCount + 0x1000, fileName); cmdCount++; } void AddDesktopItems( HMENU hMenu, char* folder) { char buf1[MAX_PATH-1]; char buf2[MAX_PATH-1]; int dirs = 0; HMENU hSubMenu; strcat( strcpy( buf1, folder), "*.*"); for (int scanCount = 0; scanCount < 2; scanCount++) { WIN32_FIND_DATA fhData; HANDLE fh = FindFirstFile( buf1, &fhData); if (fh == INVALID_HANDLE_VALUE) continue; do { if( fhData.cFileName[0] == '.') continue; if( (scanCount == 0) && (fhData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { dirs++; hSubMenu = CreateMenu(); strcat( strcat( strcpy( buf2, folder), fhData.cFileName), "\\"); AddDesktopItems( hSubMenu, buf2); InsertMenu( hMenu, -1, MF_BYPOSITION | MF_POPUP, (int)hSubMenu, fhData.cFileName); } else if( (scanCount == 1) && !(fhData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { AddCommand( hMenu, folder, fhData.cFileName); } } while (FindNextFile( fh, &fhData)); FindClose( fh); if( scanCount == 0 && dirs != 0) AppendMenu( hMenu, MF_SEPARATOR, 0, NULL); } } BOOL GetDeskTopFolder() { BOOL rval = FALSE; HKEY key; static char shellFold[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; if( RegOpenKeyEx( HKEY_CURRENT_USER, shellFold, 0, KEY_READ, &key) == 0) { if( RegQueryValueEx( key, "Desktop", NULL, NULL, (unsigned char*)dtfBuf, &dtfBufLen) == 0) { strcat( dtfBuf, "\\"); rval = TRUE; } } RegCloseKey( key); return rval; } int PASCAL WinMain( HANDLE hInst, HANDLE hPrevInst, LPSTR cmdParam, int nCmdShow) { hI = hInst; HWND hWnd; MSG msg; WNDCLASS wndClass; // if already running, cancel if( FindWindow( appName, NULL)) { Panic( "Program is already running"); return 0; } // find the desktop location if( !GetDeskTopFolder()) { Panic( "Can't get desktopfolder"); return 0; } // register window wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WndProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = hInst; wndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION); wndClass.hCursor = LoadCursor( NULL, IDC_ARROW); wndClass.hbrBackground = GetStockObject( WHITE_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = appName; RegisterClass( &wndClass); hWnd = CreateWindow( appName, appName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL); if (hWnd != 0) { ShowWindow( hWnd, SW_HIDE); // ShowWindow( hWnd, nCmdShow); // UpdateWindow( hWnd); while (GetMessage( &msg, NULL, 0, 0)) { TranslateMessage( &msg); DispatchMessage( &msg); } } return msg.wParam; } long FAR PASCAL WndProc( HWND hWnd, UINT message, UINT wParam, LONG lParam) { int cmd = LOWORD( wParam); switch( message) { // set up tray icon case WM_CREATE: nid.cbSize = sizeof( nid); nid.hWnd = hWnd; nid.uID = 0; nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; nid.uCallbackMessage = WM_USER; nid.hIcon = LoadIcon( hI, MAKEINTRESOURCE(IDI_QS)); if( nid.hIcon == NULL) Panic( "Null icon"); strcpy( nid.szTip, appName); Shell_NotifyIcon( NIM_ADD, &nid); break; case WM_COMMAND: switch( cmd) { case 'Q': PostMessage( hWnd, WM_CLOSE, 0, 0); break; case 'A': Panic( "Dave Jewell's Quick Start (EXE magazine July 1996)\nImplemented in VC++ by John Cant\nPHD Computer Consultants Ltd.\nVersion 1.1"); break; case 'D': ShellExecute( 0, NULL, dtfBuf, NULL, NULL, SW_SHOWNORMAL); break; case 'E': ShellExecute( 0, "Explore", "C:\\", NULL, NULL, SW_SHOWNORMAL); break; // case 'P': WinExec( "rundll32.exe Shell32.dll, Control_RunDLL desk.cpl,,3", SW_SHOWNORMAL); // break; case 'P': WinExec( "Control", SW_SHOWNORMAL); break; default: if( cmd >= 0x1000) ShellExecute( 0, NULL, commands[ cmd & 0xff], NULL, NULL, SW_SHOWNORMAL); break; } break; // destroy tray icon case WM_DESTROY: Shell_NotifyIcon( NIM_DELETE, &nid); PostQuitMessage( 0); return 0; // tray command case WM_USER: if( lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN) { HMENU pm; POINT pt; GetCursorPos( &pt); // free up commands memory for( int ii = 0; ii < cmdCount; ii++) delete commands[ii]; cmdCount = 0; pm = CreatePopupMenu(); AddDesktopItems( pm, dtfBuf); AppendMenu( pm, MF_SEPARATOR, 0, NULL); AppendMenu( pm, 0, 'P', "Open Control Panel..."); AppendMenu( pm, 0, 'D', "Open Desktop as a Window ..."); AppendMenu( pm, 0, 'E', "Open Explorer"); AppendMenu( pm, MF_SEPARATOR, 0, NULL); AppendMenu( pm, 0, 'A', "About"); AppendMenu( pm, 0, 'Q', "Exit"); SetForegroundWindow( hWnd); if( TrackPopupMenu( pm, TPM_BOTTOMALIGN | TPM_RIGHTALIGN, pt.x, pt.y, 0, hWnd, NULL)) SetForegroundWindow( hWnd); DestroyMenu( hWnd); } break; } return DefWindowProc( hWnd, message, wParam, lParam); }