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;