System tray program

xiaoxiao2021-03-06  23

System tray program

Function with system tray communication: Shell_NotifyiCon (DWORD DWMESSAGE, PNOTICONDATA PNID) The first parameter dwMessage can take the following value: (1) NIM_ADD Add an icon to the tray; (2) NIM_MODIFY Modify the icon in the tray; (3) NIM_DELETE Remove an icon from the tray. The second parameter is a pointer to the Notifyicondata structure. The prototype of this structure is: typedef struct_notifyicondata {dword chsize; // The size of the structure must give hWnd hwnd in the program; // To receive the window handle of the tray message UINT UID; / / The tray icon ID defined in the application, this parameter Used as identifying uint uflags; // set attribute, low three meaning, 0 --- 7, as follows: // First #define nif_message 0x1, indicating that ucallbackMessage parameter is valid // Second #define nif_icon 0x2, indicating Hicon is valid // third #define nif_tip 0x4, indicating the SZTip parameter valid uint ucallbackMessage; // Custom message ID value, must not emphasize with the existing message ID. Hicon Hicon; // Displays the handle of the ICON on the system tray, which can be used for iDi_winlogo, etc. Char Sztip [64]; // The prompt string for the icon display. NOTIFYICONDATA;

In order to receive a notification message from the tray, UCALLBACKMESSAGE can be set to the defined message ID value, and set

Nif_message logo. This way when the user moves or presses the mouse on the icon, the message

MessageID is the value defined in UcallbackMessage; WPARAM is the value of the defined UID; lParam is a mouse event,

Such as WM_LBUTTONDOWN. An example under WTL: #define WM_TRAYICON WM_APP 100MESSAGE_HANDLER (WM_TRAYICON, ONTRYICON)

Lresult CMAINFRAME :: Ontrayicon (Uint Umsg, WParam WParam, LParam Lparam, Bool &

Bhandled) {uint umousemsg = (uint) LParam; switch (umousemsg) {copy wm_lbuttondown: MessageBox ("left", "left", mb_ok); break; case wm_rbuttondown: MessageBox ("right", "right", MB_OK); Break; default: Break;

Return 0;}

Bool CMAINFRAME :: addtrayicon () {hicon hicon = loading (_Module.m_hinstResource, makeintResource

(IDR_MAINFRAME)); char lpszTip [] = _T ( "TrayIcon"); NOTIFYICONDATA tnid; tnid.cbSize = sizeof (NOTIFYICONDATA); tnid.hWnd = m_hWnd; tnid.uID = IDR_MAINFRAME; tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP ; Tnid.ucallbackMessage = WM_TRAYICON; TNID.HICON = Hicon; lstrcpyn (TNID.SZTIP, LPSZTIP, SIZEOF (TNID.SZTIP)); Return shell_notifyicon (NIM_ADD, & TNID);}

Bool CMAINFRAME :: deleteTrayicon () {Notifyicondata Tnid; Tnid.cbsize = sizeof (notifyicondata); tnid.hwnd = m_hwnd; tnid.uid = idR_mainframe;

Return shell_notifyicon (nim_delete, & tnid);

转载请注明原文地址:https://www.9cbs.com/read-65186.html

New Post(0)