Minimize the implementation of pallets and minimize the implementation of pallets
I found it useful in the book and noted it down.
First, the basic principle of minimizing the tray is to hide the main form of the application, and then draw the application icon in the tray. Then add some event processing for the tray icon.
The core function is the shell_policyicon () function, which transmits messages to the system, adds, modifies, or deletes icons in the tray area. Prototype:
Winshellapi bool winapi shell_policyicon (
DWORD dwMessage,
PNOTIFYCONDATA pnid
);
Among them, the dwMessage flag function is NIM_ADD/NIM_DELETE/NIM_MODIFY.
Pnid is the structure of the icon information that minimizes the program to the tray:
Typedef struct _ policycondata {
DOWRD cbSize; // The length of the Structure
HWND hWnd;
UINT uID; // icon ID
UINT uFlags; // indicates the validity of other member data?
UINT uCallbackMessage; // a message is sent to the window when you click the tray area icon.
HICON hIcon; // icon handle
Char szTip [64]; // text displayed when you move the cursor over the tray icon
} NOTIFYICONDATA, * ppolicyicondata;
Related code:
...
NOTIFYICONDATA nid;
Nid. cbSize = (DWORD) sizeof (policyicondata );
Nid. hWnd = this-> m_hWnd;
Nid. uID = IDR_MAINFRAME;
Nid. uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; // I don't understand this sentence?
Nid. uCallbackMessage = WM_CALL;
Nid. hIcon = LoadIcon (AfxGetInstanceHandle (), MAKEINTRESOURCE (IDR_MAINFRAME ));
Strcpy (nid. szTip, "MyApp ");
Shell_policyicon (NIM_ADD, & nid );
ShowWindow (SW_HIDE); // hide the Main Window
...
Next, we will customize the message WM_CALL, which is described in an article about the method. Note that the wParam receiving icon ID of the callback message is specified, and lParam receives the mouse action.
In addition, when the program is all closed, the tray should also be deleted, and the code is almost identical.