Update of /cvsroot/popfile/windows/POPFileIcon In directory sc8-pr-cvs1:/tmp/cvs-serv17976 Added Files: icon.cpp icon.def icon.h icon.rc icon.sln icon.suo icon.vcproj popfile.ico resource.h stdafx.cpp stdafx.h Log Message: First version of POPFileIcon DLL --- NEW FILE: icon.cpp --- //--------------------------------------------------------------------------- // // icon.cpp // // Simple DLL that puts an icon in the Windows system tray and handles // a popup menu and double click events. Used by POPFile so that it can // have a tray icon like so many other Windows applications. // // Copyright (c) 2003 John Graham-Cumming // //--------------------------------------------------------------------------- FreeLibrary( #include "stdafx.h" #include "icon.h" #include "resource.h" // Name of the window class for our parent window char * gClassName = "POPFile.NOTIFYICONDATA.hWnd"; // These two bools (one which indicates that Shutdown has been selected // the other the UI) are set by the popup menu handle and read by a // call to GetMenuMessage bool gShutdown = false; bool gUI = false; // Used to store information about the POPFile icon displayed // in the system tray NOTIFYICONDATA gNid; // The number of processes that have attached to us int gProcessCount = 0; // Handle of the Window associated with the tray icon HWND gHwnd = 0; // The instance of this DLL obtained from DllMain HINSTANCE ghInst; // Message ID sent when the system tray icon needs to send a message #define UWM_SYSTRAY ( WM_USER + 1 ) //--------------------------------------------------------------------------- // // wndProc__ // // Windows procedure for the invisible window we use to handle the messages // pertaining to the system tray icon. It's job is to spot right click // to show the menu and the left double click to go to the UI // //--------------------------------------------------------------------------- LRESULT CALLBACK wndProc__( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch (message) { case UWM_SYSTRAY: switch (lParam) { case WM_RBUTTONUP: { POINT pt; GetCursorPos(&pt); HMENU hMenu = LoadMenu( ghInst, MAKEINTRESOURCE(IDM_POPFILE)); HMENU hPopUp = GetSubMenu( hMenu, 0); SetForegroundWindow( hwnd ); switch ( TrackPopupMenu( hPopUp, TPM_RETURNCMD | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL ) ) { case IDM_EXIT: gShutdown = true; break; case IDM_UI: gUI = true; break; default: break; } PostMessage( gHwnd, 0, 0, 0); DestroyMenu( hMenu ); } break; case WM_LBUTTONDBLCLK: gUI = true; break; } return TRUE; } return DefWindowProc( hwnd, message, wParam, lParam ); } //--------------------------------------------------------------------------- // // ShowPOPFileIcon // // Puts the POPFile icon in the system tray // //--------------------------------------------------------------------------- void ShowPOPFileIcon__() { WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = wndProc__; wc.cbClsExtra = wc.cbWndExtra = 0; wc.hInstance = ghInst; wc.hIcon = LoadIcon( ghInst, MAKEINTRESOURCE(IDI_POPFILE)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszMenuName = NULL; wc.lpszClassName = gClassName; wc.hIconSm = (HICON)LoadImage(ghInst, MAKEINTRESOURCE(IDI_POPFILE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0); RegisterClassEx( &wc ); gHwnd = CreateWindowEx( 0, gClassName, gClassName, WS_POPUP, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, ghInst, NULL); gNid.cbSize = sizeof(NOTIFYICONDATA); gNid.hWnd = gHwnd; gNid.uID = 1; gNid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; gNid.uCallbackMessage = UWM_SYSTRAY; gNid.hIcon = (HICON)LoadImage( ghInst, MAKEINTRESOURCE(IDI_POPFILE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0); strcpy( gNid.szTip, "POPFile" ); Shell_NotifyIcon( NIM_ADD, &gNid ); } //--------------------------------------------------------------------------- // // HidePOPFileIcon // // Removes the POPFile icon from the system tray // //--------------------------------------------------------------------------- void HidePOPFileIcon__() { Shell_NotifyIcon( NIM_DELETE, &gNid ); DestroyWindow( gHwnd ); UnregisterClass( gClassName, ghInst ); } //--------------------------------------------------------------------------- // // GetMenuMessage // // Called to get any message from the icon. Returns 0 to indicate no // message, 1 to indicate shutdown and 2 to indicate go to UI // //--------------------------------------------------------------------------- int APIENTRY GetMenuMessage() { if ( gShutdown ) { return 1; } if ( gUI ) { return 2; } return 0; } //--------------------------------------------------------------------------- // // DllMain // // Standard Windows DLL interface function // //--------------------------------------------------------------------------- BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { // When the first process attaches we show the icon, when // the last process detaches we kill off the icon. We do // not care about new threads switch ( ul_reason_for_call ) { case DLL_PROCESS_ATTACH: gProcessCount += 1; if ( gProcessCount == 1 ) { ghInst = (HINSTANCE) hModule; ShowPOPFileIcon__(); } break; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: gProcessCount -= 1; if ( gProcessCount == 0 ) { HidePOPFileIcon__(); } break; } return TRUE; } --- NEW FILE: icon.def --- LIBRARY POPFileIcon EXPORTS GetMenuMessage @1 --- NEW FILE: icon.h --- //--------------------------------------------------------------------------- // // icon.h // // Simple DLL that puts an icon in the Windows system tray and handles // a popup menu and double click events. Used by POPFile so that it can // have a tray icon like so many other Windows applications. // // Copyright (c) 2003 John Graham-Cumming // //--------------------------------------------------------------------------- int APIENTRY GetMenuMessage(); --- NEW FILE: icon.rc --- // Microsoft Visual C++ generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // English (U.S.) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) #endif //_WIN32 #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE BEGIN "resource.h\0" END 2 TEXTINCLUDE BEGIN "#include ""afxres.h""\r\n" "\0" END 3 TEXTINCLUDE BEGIN "\r\n" "\0" END #endif // APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Menu // IDM_POPFILE MENU BEGIN POPUP "PopUpMenu" BEGIN MENUITEM "POPFile &UI", IDM_UI MENUITEM SEPARATOR MENUITEM "&Shutdown POPFile", IDM_EXIT END END ///////////////////////////////////////////////////////////////////////////// // // Icon // // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDI_POPFILE ICON "popfile.ico" #endif // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED --- NEW FILE: icon.sln --- Microsoft Visual Studio Solution File, Format Version 7.00 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icon", "icon.vcproj", "{1930D96E-489F-4598-B76D-318AFEF27BE0}" EndProject Global GlobalSection(SolutionConfiguration) = preSolution ConfigName.0 = Debug ConfigName.1 = Release EndGlobalSection GlobalSection(ProjectDependencies) = postSolution EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution {1930D96E-489F-4598-B76D-318AFEF27BE0}.Debug.ActiveCfg = Debug|Win32 {1930D96E-489F-4598-B76D-318AFEF27BE0}.Debug.Build.0 = Debug|Win32 {1930D96E-489F-4598-B76D-318AFEF27BE0}.Release.ActiveCfg = Release|Win32 {1930D96E-489F-4598-B76D-318AFEF27BE0}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection GlobalSection(ExtensibilityAddIns) = postSolution EndGlobalSection EndGlobal --- NEW FILE: icon.suo --- (This appears to be a binary file; contents omitted.) --- NEW FILE: icon.vcproj --- <?xml version="1.0" encoding = "Windows-1252"?> <VisualStudioProject ProjectType="Visual C++" Version="7.00" Name="icon" ProjectGUID="{1930D96E-489F-4598-B76D-318AFEF27BE0}" Keyword="Win32Proj"> <Platforms> <Platform Name="Win32"/> </Platforms> <Configurations> <Configuration Name="Debug|Win32" OutputDirectory="Debug" IntermediateDirectory="Debug" ConfigurationType="2" CharacterSet="2"> <Tool Name="VCCLCompilerTool" Optimization="0" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;ICON_EXPORTS" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="1" UsePrecompiledHeader="3" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="4"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" OutputFile="c:/popfile2/engine/Platform/POPFileIcon.dll" LinkIncremental="2" ModuleDefinitionFile="icon.def" GenerateDebugInformation="TRUE" ProgramDatabaseFile="$(OutDir)/icon.pdb" SubSystem="2" ImportLibrary="$(OutDir)/POPFileIcon.lib" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> </Configuration> <Configuration Name="Release|Win32" OutputDirectory="Release" IntermediateDirectory="Release" ConfigurationType="2" CharacterSet="2"> <Tool Name="VCCLCompilerTool" Optimization="2" InlineFunctionExpansion="1" OmitFramePointers="TRUE" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;ICON_EXPORTS" StringPooling="TRUE" RuntimeLibrary="0" EnableFunctionLevelLinking="TRUE" UsePrecompiledHeader="3" WarningLevel="3" Detect64BitPortabilityProblems="TRUE" DebugInformationFormat="3"/> <Tool Name="VCCustomBuildTool"/> <Tool Name="VCLinkerTool" OutputFile="c:/popfile2/engine/Platform/POPFileIcon.dll" LinkIncremental="1" ModuleDefinitionFile="icon.def" GenerateDebugInformation="TRUE" SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" ImportLibrary="$(OutDir)/POPFileIcon.lib" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> <Tool Name="VCPostBuildEventTool"/> <Tool Name="VCPreBuildEventTool"/> <Tool Name="VCPreLinkEventTool"/> <Tool Name="VCResourceCompilerTool"/> <Tool Name="VCWebServiceProxyGeneratorTool"/> <Tool Name="VCWebDeploymentTool"/> </Configuration> </Configurations> <Files> <Filter Name="Source Files" Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"> <File RelativePath="icon.cpp"> </File> <File RelativePath="icon.def"> </File> <File RelativePath="stdafx.cpp"> <FileConfiguration Name="Debug|Win32"> <Tool Name="VCCLCompilerTool" UsePrecompiledHeader="1"/> </FileConfiguration> <FileConfiguration Name="Release|Win32"> <Tool Name="VCCLCompilerTool" UsePrecompiledHeader="1"/> </FileConfiguration> </File> </Filter> <Filter Name="Header Files" Filter="h;hpp;hxx;hm;inl;inc"> <File RelativePath="icon.h"> </File> <File RelativePath="resource.h"> </File> <File RelativePath="stdafx.h"> </File> </Filter> <Filter Name="Resource Files" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"> <File RelativePath="icon.rc"> </File> <File RelativePath="popfile.ico"> </File> </Filter> </Files> <Globals> </Globals> </VisualStudioProject> --- NEW FILE: popfile.ico --- (This appears to be a binary file; contents omitted.) --- NEW FILE: resource.h --- //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. // Used by icon.rc // #define IDI_POPFILE 5 #define IDM_POPFILE 101 #define IDM_EXIT 102 #define IDM_UI 103 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 105 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1001 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif --- NEW FILE: stdafx.cpp --- //--------------------------------------------------------------------------- // // stdafx.cpp // // Copyright (c) 2003 John Graham-Cumming // //--------------------------------------------------------------------------- #include "stdafx.h" --- NEW FILE: stdafx.h --- //--------------------------------------------------------------------------- // // stdafx.h // // Copyright (c) 2003 John Graham-Cumming // //--------------------------------------------------------------------------- #pragma once #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files: #include <windows.h> #include <shellapi.h> |