Windows工作列系統托盤表徵圖示範程式

來源:互聯網
上載者:User

許多應用程式,如IME管理器、殺毒軟體等均在工作列布告區中放置一個有自已特色的表徵圖,該表徵圖讓使用者知道有一個背景程式正在運行,同時也提供了一種修改系統設定的快捷方法,本文將以C++ Builder為例簡述它的實現方法。

開啟一個新工程,將工程檔案取名為test、單元檔案取名為main。在視窗上放置二個按鈕、一個標籤,其屬性按如下設定

組件      屬性     值

Label1    Caption  按OK按鈕...終止程式

OKButton   Caption  &OKButton

CancelButton Caption  &CancelButton

開啟檔案main.h,加入斜體部分聲明(以手工輸入部分均以斜體表示,以下同)

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

切換到main.cpp,加入以下函數及聲明

#include
#pragma hdrstop
#include
#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm1::AddTray()//建立工作列布告區表徵圖
{
NOTIFYICONDATA icondata;①
memset(&icondata,0,sizeof(icondata));②
icondata.cbSize=sizeof(icondata);
icondata.hWnd=Handle;③
strncpy(icondata.szTip,"我的工作",sizeof(icondata.szTip));④
Application->Icon->LoadFromFile("e:\\yxg\\map\\system\\ico\\yxg.ico");
icondata.hIcon=Application->Icon->Handle; ⑤
icondata.uCallbackMessage=ugIconMessage;⑥
icondata.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;⑦
Shell_NotifyIcon(NIM_ADD,&icondata);⑧
}
void TForm1::DeleteTray()//刪除工作列布告區表徵圖
{
NOTIFYICONDATA icondata;
memset(&icondata,0,sizeof(icondata));
icondata.cbSize=sizeof(icondata);
icondata.hWnd=Handle;
Shell_NotifyIcon(NIM_DELETE,&icondata); ⑧
}
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
if(Message.Msg==ugIconMessage)//如果產生的是與該表徵圖相關的訊息
{
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);
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.