How is the program displayed in the system tray?

Source: Internet
Author: User
Ticon * myicon = new ticon;
Myicon-> loadfromfile (extractfilepath (paramstr (0) +/"// day 1.ico /");

Tpolicyicondata icondata;
// The size of the custom policyicon variable
Icondata. cbsize = sizeof (icondata );
// If you want the message generated by the pallet program to be processed by any form, let WND point to the form handle.
Icondata. hwnd = mainform-> handle;
// Differentiate the ID of another system tray Applet
Icondata. uid = 100;
// The handle of the tray icon. Based on this handle, you can add, modify, and delete icons.
Icondata. hicon = myicon-> handle;
/* Uflags: A flag indicating the properties of the currently created pallet Program
Nif_icon indicates that the currently set icon (that is, the value of hicon) is valid.
Nif_message indicates that the currently set system message (that is, the ucallbackmessage value) is valid.
Nif_tip indicates that the currently set prompt bar (that is, the value of sztip) is valid.
*/
Icondata. uflags = nif_icon | nif_message | nif_tip;

/* Ucallbackmessage: This is the most important of the seven parts. Specify a callback message, that is, define a message name, when you click or right-click the tray icon, a message name defined in ucallbackmessage is sent to the form pointed to by WND, then you define a message-out function in the program to process the message. In this way, the entire message process in Windows is processed */
Icondata. ucallbackmessage = wm_user + 100;
// Sztip is the prompt that appears when you place your mouse on the small icon of the taskbar tray.
Strcpy (icondata. sztip,/"the URL management expert clicks the left button to display the form /");
Shell_policyicon (nim_add, & icondata );
Setwindowlong (Application-> handle, gwl_exstyle, ws_ex_toolwindow );

At the same time, create a message event for the ticon object in the main form:
Public:
Void virtual _ fastcall iconclick (tmessage & MSG );
Bool systemshutdown (uint uflag );
Begin_message_map
Message_handler (wm_user + 100, tmessage, iconclick)
End_message_map (tform)
//-----------------------------------------------------------------
Void _ fastcall tmainform: iconclick (tmessage & MSG)
{
Tpoint po;
If (msg. lparam = wm_lbuttondown)
{
This-> show ();
}
If (msg. lparam = wm_rbuttonup)
{
Getcursorpos (& po); // get the coordinate value of the current mouse
Advpopupmenu1-> popup (PO. X, Po. y );
}
}
//-------------------------------------------------------------------

End Time:
Tpolicyicondata icondata;
Icondata. cbsize = sizeof (icondata );
Icondata. hwnd = mainform-> handle;
Icondata. uid = 100;
Shell_policyicon (nim_delete, & icondata );
Delete myicon;

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.