Tray area icon programming method

xiaoxiao2021-03-06  14

/// Tray area icon programming method //// copyright (c) 2005.3.11 Butterfly Valley Software HAOBING All Rights Reserved ///

1. Hide the main window and create program icon in the tray area: notifyicondata nc; nc.cbsize = sizeof (notifyicondata); nc.hicon = AFXGetApp () -> loadicon (idR_mainframe); nc.hwnd = m_hwnd; strcpy Nc.sztip, "catch"); nc.ucallbackMessage = WM_NC; nc.uflags = nif_icon | nif_message | nif_tip; nc.uid = IDC_NC; shell_notifyicon (nim_add, & nc); showwindow (sw_hide); // Hide Window

Input on the CPP file: #define wm_nc wm_user 10 #define IDC_NC 1002

Principle: Implementing the key function of this feature in the status bar in the status bar is the shell_notifyicon function, which has two parameters: front a specified you want to join, delete, or modify the icon, named NIM_ADD, NIM_DELETE and NIM_MODIFY; later is one Pointer to the NOTIFYICONDATA type variable. The Notifyicondata data structure describes the properties of the icons displayed in the status bar. CBSIZE is the size of the Notifyicondata structure; Hicon is the handle of the icon; HWnd is the handle of the current window; uCallbackMessage is a custom message that there is a message in the square area belonging in the icon. For example, when you click the icon, the system will Send a message to uCallbackMessage, we can use ON_MESSAGE (XXX, XXX) to call the response function; uflags is a set of parameters, where nif_icon specifies HICON valid, nif_mesage is valid, nif_tip specifies Sztip effective; UID Specify the icon identification The text information specified by SZTIP is displayed in a floating mode when you move the mouse to the icon.

2. Double-click the tray area program icon to play the master window to find the paragraph that defines the message response function in the implementation of the file header file (.h), that is, inserted in Begin_Message_Map (CclipboardDlg, CDIALOG) and END_MESSAGE_MAP:

ON_MESSAGE (WM_NC, ONNC) The protected area definition function in the header file (.h) is as follows: AFX_MSG Void ONNC (WPARAM WPARAM, LPARAM LPARAM); in the CPP file is implemented as follows: (for example, CclipboardDLG) Void CclipboardDLG :: ONC (WPARAM WPARAM, LPARAM LPARAM) {if (lparam == wm_lbuttondblclk) showwindow;} 3, the method of automatically release the tray area icon after closing the program is added in the onDestroy function or the folding function. The following: // delete the system area icon NOTIFYICONDATA nc; nc.cbSize = sizeof (NOTIFYICONDATA); nc.hIcon = AfxGetApp () -> LoadIcon (IDR_MAINFRAME); nc.hWnd = m_hWnd; nc.uCallbackMessage = WM_NC; nc.uFlags = NIF_ICON | Nif_message | nif_tip; nc.uid = IDC_NC; Shell_Notifyicon (Nim_Delete, & NC);

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

New Post(0)