Minimize the implementation of pallets and minimize the implementation of pallets

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.