Customize the DLL of the taskbar Tray
Luo chaohui (floating white clouds) 2009.06.08
Http://www.cppblog.com/kesalin
(Indicate the author and source when reprinting. Do not use it for commercial purposes without permission)
Download source file: click here
Google Project: http://code.google.com/p/luotasktray/
By customizing the DLL (modifying the icon and inserting menu, you can easily replace the work), you can easily use the customized taskbar tray in the new project, in this way, you need to complete the desktop tray code every time you write a desktop program. The taskbar tray created by this DLL is in non-blocking mode with the main window.
Effect
Display the taskbar Tray:
Response menu event:
How to customize your own DLL?
In two steps, replace the icon and the replacement menu.
Step 1: Replace the icon.
Open tasktraywindow. h In the luotasktray project, find the following position, and change it to your own icon.
// Load icon <br/> hicon =: loadicon (null, idi_application); <br/> // todo: load your icon here! <Br/> // hicon =: loadicon (hinstance) getwindowlongptr (gwlp_hinstance), makeintresource (idi_icon1 ));
Step 2: replace the menu.
Open tasktraywindow. h In the luotasktray project, find the following location, and modify it to your own menu item.
// Todo: insert your menu items here! <Br/> int I = 0; <br/> Popup. insertmenu (I ++, mf_byposition, luotasktray: ttm_exit, _ T ("exit "));
How to use custom DLL?
Step 1: Include the header file and import Lib.
// Include header files for luotasktray. <br/> # include "include/luotasktray. H "<br/> # include" include/luotasktrayimport. H "<br/> // import lib <br/> # ifdef _ debug <br/> # pragma comment (Lib," bin/luotasktray_debug.lib ") <br/> # else <br/> # pragma comment (Lib, "bin/luotasktray. lib ") <br/> # endif <br/>
Step 2: load the DLL and initialize it. When the program exits, clean it and uninstall the DLL.
Luotasktray: uactivator * g_pluotasktray; <br/>/** <br/> * @ brief: Initialize luotasktray <br/> * @ Param: <br/> * @ return: bool <br/> */<br/> bool initluotasktray () <br/> {<br/> hresult hrslt = luotasktray :: activate_import (<br/> L "Activator", <br/> (void **) & g_pluotasktray); <br/> If (failed (hrslt )) {<br/> return false; <br/>}< br/> hrslt = g_pluotasktray-> initialize (); <br/> If (failed (hrslt )) {<br/> g_pl Uotasktray-> uninitialize (); <br/> g_pluotasktray = NULL; <br/> return false; <br/>}< br/> return true; <br/>}< br/>/** <br/> * @ brief: uninitialize luotasktray <br/> * @ Param: <br/> * @ return: <br/> */<br/> void uninitluotasktray () <br/> {<br/> If (g_pluotasktray! = NULL) {<br/> g_pluotasktray-> uninitialize (); <br/> g_pluotasktray = NULL; <br/>}< br/>}
Step 3: Create a taskbar tray.
If (g_pluotasktray) {<br/> luotasktray: ucreateparam Param = {0, }; <br/> param. hwnd = * This; <br/> param. callbackmessage = luotasktray: callback; // callback message <br/> hresult hrslt = g_pluotasktray-> createtasktray (& PARAM); <br/> If (succeeded (hrslt )) {</P> <p >}< br/>}
Step 4: callback message (menu message)
Message_handler (luotasktray: wm_task_tray_callback, ontasktraycallback) <br/> lresult ontasktraycallback (uint umsg, wparam, lparam, Boolean & bhandled) <br/>{< br/> int cmd = (INT) wparam; <br/> hwnd = (hwnd) lparam; <br/> switch (CMD) {<br/> case luotasktray: ttm_exit: <br/> // do something <br/> break; <br/>}< br/> return 0; <br/>}< br/>