VC System Tray program to minimize the window to System Tray

Source: Internet
Author: User

 

VC System TrayProgramMinimize windows to system pallets

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 );.

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.