Develop applications with Windows Task Column Tablet icons

zhaozj2021-02-11  199

Developed the application of the Windows Task Column Troubleshooting Icon Beijing 1303 Mailbox 15 Box Yin Help Many applications, such as input method manager, anti-virus software, etc. Place a self-featured icon in the task column, this icon makes users Knowing a background program is running, but also provides a shortcut method for modifying the system settings. This article will be a brief description of its implementation method as an example of C Builder. Open a new project, name Test named, and the unit file is main.

Place the two buttons on the window, a tab, its property is set as follows, the component attribute value, Label1 CAPTION Press OK button ... Terminal Okbutton Caption & Okbutton CancelButton Caption & CancelButton Open file main.h, add the bevel part declaration (in manual input portions are shown in italics, the same applies hereinafter) class TForm1: public TForm {__published: // IDE-managed Components TButton * OKButton; TButton * CancelButton; TLabel * Label1; void __fastcall FormCreate (TObject * Sender); void __fastcall FormDestroy (TObject * Sender); void __fastcall OKButtonClick (TObject * Sender); void __fastcall CancelButtonClick (TObject * Sender); private: // User declarations unsigned ugIconMessage; void AddTray (); void DeleteTray (); protected: virtual void __fastcall WndProc (Messages :: TMESSAGE & Message); public: // user declarations __fastcall tform1 (tComponent * Owner;}; switch to main.cpp, add the following functions and declaration #include #pragma hdrstop #include "main.h" // ----- -------------------------------------------------- -------------------- #pragma package (smart_init) #pragma resource "* .dfm" TFORM1 * FORM1; // -------- -------------------------------------------------- ----------------- __fastcall tform1 :: tform1 (tComponent * Owner: TFORM (OWNER) {} // -------------- -------------------------------------------------- ----------- Void TForm1 :: AddtTray () // Create a taskbar tetle icon {Notifyicondata iconData; 1 MEMSET (IconData); 2 icondata.cbsize = sizeof iconData); icondata.hwnd = handle; 3 Strncpy (iCondata.sztip, "My Task", sizeof (icholda.sztip)); 4 Application-> icon-> loadingFromFile ("E: // yxg // map // System // ICO // Yxg.ico "); iconData.hicon = Application-> icon-> handle; 5 icondata.ucallbackMessage =

ugIconMessage; ⑥ icondata.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; ⑦ Shell_NotifyIcon (NIM_ADD, & icondata); ⑧} void TForm1 :: DeleteTray () // Delete the task bar announcement area icon {NOTIFYICONDATA icondata; memset (& icondata, 0, sizeof ( Icondata); icondata.cbsize = sizeof (icondata); icondata.hwnd = handle; shell_notifyicon (nim_delete, & icondata); 8}

Void __fastcall tform1 :: WndProc (Messages :: TMESSAGE & Message) {if (message.msg == ugiconMessage) // If it is generated, a message related to this icon {if (message.lparam == wm_lbuttondblclk) Application-> Terminate ); ⑨ IF (message.lparam == wm_rbuttondblclk) {showwindow (Application-> Handle, SW_SHOW); // Application-> ShowMainform = true; Form1-> Visible = true;} return;}

TFORM :: WndProc (Message);} 1 Apply for structural variables of a taskbar taking area icon; 2 Clear the contents of the structure variable; 3 get the handle of the current window; 4 Enter the prompt string when the mouse is passed through the icon; 5 The self-love icon file is an icon of the task bar queue; 6 get the callback information variable; 7 When the member Hicon, UcallbackMessage and Sztip in the structural variable are wrong; 8 call function shell_notifyicon () in the task bar Distribution or delete an icon; ⑨ When the left mouse button double-click this icon, the termination program is running; We know that all TwinControl derived VCL classes have a WndProc function, calling this function to send a message and received by the associated window, WndProc is defined as a virtual function, such a derived class can define its own WndProc functions Instead of the WndProc function of its parent class. Here, the message related to the task bar cloth icon is processed by the wndproc function of the subclass, otherwise call the WndProc processing of the parent class. In the event of Form1 OnCreate added the following code: void __fastcall TForm1 :: FormCreate (TObject * Sender) {ugIconMessage = RegisterWindowMessage ( "IconNotify"); ① AddTray (); ② Form1-> Visible = false; ③} ① call the RegisterWindowMessage ( ) Function to create a unique message number to ensure that there is no conflict; 2 Create icons in the task bar queue; 3 Display the form; add the deleTray () function to delete icons in the ONDESTROY event in Form1. Add the OKButton's onclick event to the CancelButton button to hide the main window and the termination program. Void __fastcall tform1 :: okbuttonclick (tobject * sender) {form1-> visible = false; showWindow (Application-> Handle, SW_HIDE); Application-> ShowMainform = false;} // ----------- -------------------------------------------------- -------------- Void __fastcall tform1 :: canbelButtonClick (TOBJECT * Sender) {Application-> Terminate ();} Finally, add two lines of code in the WinMain function to start running Hide the main form.

转载请注明原文地址:https://www.9cbs.com/read-4919.html

New Post(0)