Some time ago, the system was used to drag the disk, So I studied it and recorded it here, so that I would not forget to forget it later. Define a structure variable in the class firstNotifyicondata pnid;ThenOninitdialogInitialize Pnid. cbsize = (DWORD) sizeof (policyicondata); // size of the struct Pnid. hwnd = m_hwnd; // window handle Pnid. uid = (uint) m_hicon; // icon handle Pnid. uflags = nif_icon | nif_message | nif_tip; // the icon is valid. | the custom message is valid. | the mouse points to the displayed text. Pnid. ucallbackmessage = wm_mymessage; // custom message name Pnid. hicon = m_hicon; // icon handle Strcpy (pnid. sztip, "this is a test"); // point the cursor to the displayed text Minimize to system drag, which defines a windowOnsizeEvent Void cmydlg: onsize (uint ntype, int CX, int CY) { Cdialog: onsize (ntype, CX, CY ); // Todo: Add a message processing program hereCode If (ntype = size_minimized) // if the event is minimized { Shell_policyicon (nim_add, & pnid); // Add an icon in the tray Area Showwindow (sw_hide); // hide the Main Window } } To restore the cmydlg. H, perform the following operations: # Define wm_mymessage wm_user + 101 // defines the custom message. This value must be greater than 100. Afx_msg lresult onmymessage (wparam, lparam); // define the message Response Function in the class Then define message ing in cmydlg. app, and implement the function. In Begin_message_map (cmydlg, cdialog) End_message_map ()Message ing On_message (wm_mymessage, onmymessage) Then createOnmymessageFunction. Lresult cmydlg: onmymessage (wparam, lparam ){ If (lparam = wm_lbuttondown) // restore if you click the left button in the icon { Shell_policyicon (nim_delete, & pnid); // Delete the tray icon Showwindow (sw_shownormal); // display the Main Window This-> setwindowpos (& wndtopmost, swp_nomove | swp_nosize); // make the window always at the beginning } Return 0; } If you want to change the display icon, change it first.PnidThe value in the structure, and then useShell_policyicon (nim_modify, & pnid );. |