1. Add the variable in the. h file of the window class: Notifyicondata Pnid;
2, in the window class. CPP file in custom message: Wm_mymessage
3. Add code to the initialization function OnInitDialog of the window class:
Pnid.cbsize = (DWORD) sizeof (NOTIFYICONDATA);
Pnid.hwnd = m_hwnd;
Pnid.uid = (UINT) M_hicon;
Pnid.uflags = nif_icon| nif_message| Nif_tip;
Icon Valid | Custom message valid | Mouse pointing to display text valid
Pnid.ucallbackmessage = Wm_mymessage;
Pnid.hicon = M_hicon;
strcpy (Pnid.sztip, "LAN Monitoring System Client");
4. Add a message response function for Wm_mymessage:
Begin_message_map (Cclientdlg, CDialog)
On_message (Wm_mymessage,onmymessage)
On_wm_size ()//window message (added in the Class wizard)
End_message_map ()
5, the implementation of OnMyMessage function:
LRESULT cclientdlg::onmymessage (WPARAM WPARAM, LPARAM LPARAM)
{
if (LParam = = wm_lbuttondown)//If you left-click in the icon to restore
{
Shell_NotifyIcon (Nim_delete,&pnid);//delete tray icon
ShowWindow (SW_SHOWNORMAL);//Display main window
Make the window always on the front
This->setwindowpos (&wndtopmost,0,0,0,0,
swp_nomove| Swp_nosize);
}
return 0;
}
6. Add the On_wm_size () message to the dialog box in the Class Wizard and implement the OnSize function
void Cclientdlg::onsize (UINT nType, int cx, int cy)
{
Cdialog::onsize (NType, CX, CY);
if (ntype==size_minimized)//If the event is minimized
{
Shell_NotifyIcon (Nim_add,&pnid);//Add icon to Tray area
ShowWindow (sw_hide);//Hide main window
}
}
This article is from "Mu Ming" blog, please be sure to keep this source http://10437084.blog.51cto.com/10427084/1679031
Minimized window to pallet area-vc++