#include"tlhelp32.h"#include"afxdialogex.h"voidCthsmfcappdlg::onsyscommand (UINT NID, LPARAM LPARAM) {if(NID &0xfff0) ==Idm_aboutbox) {CAboutDlg dlgabout; Dlgabout.domodal (); } if(NID = =sc_minimize) { //respond to minimized events with our own messagesTomini (); } Else{Cdialogex::onsyscommand (NID, LParam); }}voidCthsmfcappdlg::tomini () {ShowWindow (sw_hide); Notifyicon.cbsize=sizeof(Notifyicondata); Notifyicon.hicon= AfxGetApp ()LoadIcon (IDR_MAINFRAME); Notifyicon.hwnd=m_hwnd; lstrcpy (Notifyicon.sztip, L"TEST"); Notifyicon.ucallbackmessage=WM_NC; Notifyicon.uflags= Nif_icon | Nif_message |Nif_tip; Shell_NotifyIcon (Nim_add,&NotifyIcon);}
LRESULT cthsmfcappdlg::onnotifymsg (WPARAM WPARAM, LPARAM LPARAM)//WPARAM receives the ID of the icon, and lparam receives the mouse's behavior{ //if (wparam! = idr_mainframe)//return 1; Switch(lparam) { CaseWm_rbuttonup://The shortcut menu pops up when you right-click, there's only one "off"{lppoint Lpoint=NewTagpoint; :: GetCursorPos (lpoint);//Get mouse positionCMenu menu; Menu. CreatePopupMenu ();//declaring a pop-up menu//Add menu item "Close", click to Send Message Wm_destroy to main window (already//hidden) to end the program. Menu. AppendMenu (mf_string, Wm_destroy, _t ("Close")); //determine the location of the pop-up menuMenu. TrackPopupMenu (Tpm_leftalign, lpoint->x, Lpoint->y, This); //Resource RecyclingHMENU HMENU =menu. Detach (); Menu. DestroyMenu (); DeleteLpoint; } Break; CaseWM_LBUTTONDBLCLK://left-click Processing { This->showwindow (Sw_show);//Simple Display main window finished } Break; } return 0;}
Reference sources
MFC Minimized to Pallet