|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
主題工具 | 顯示模式 |
2005-06-21, 04:59 PM | #1 |
版區管理員
|
用C++ Builder設計TrayIcon
請放一個TPopupMenu物件
選單內容 語法:
object N1: TMenuItem Caption = '記事本' OnClick = N1Click end object N2: TMenuItem Caption = '檔案總管' OnClick = N2Click end object N3: TMenuItem Caption = '-' end object N4: TMenuItem Caption = '離開' OnClick = N4Click end 語法:
object Form1: TForm1 Left = 192 Top = 114 Width = 696 Height = 480 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False OnActivate = FormActivate OnClose = FormClose PixelsPerInch = 96 TextHeight = 13 object PopupMenu1: TPopupMenu Left = 72 Top = 48 object N1: TMenuItem Caption = #35352#20107#26412 OnClick = N1Click end object N2: TMenuItem Caption = #27284#26696#32317#31649 OnClick = N2Click end object N3: TMenuItem Caption = '-' end object N4: TMenuItem Caption = #38626#38283 OnClick = N4Click end end end |
送花文章: 1534,
|
2005-06-21, 05:02 PM | #2 (permalink) |
版區管理員
|
Unit1.cpp內容
語法:
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::TRAYCALLBACK(TMessage& Message) { POINT MousePos; switch(Message.LParam) { case WM_RBUTTONUP: // if (GetCursorPos(&MousePos)) { PopupMenu1->PopupComponent = Form1; SetForegroundWindow(Handle); PopupMenu1->Popup(MousePos.x, MousePos.y); } break; case WM_LBUTTONUP: ::ShellExecute(::GetDesktopWindow(),"explore",NULL,NULL,NULL,SW_SHOWNORMAL); break; default: break; } TForm::Dispatch(&Message); } //--------------------------------------------------------------------------- void TForm1::ShowIcon() { Icon.cbSize=sizeof(NOTIFYICONDATA); Icon.hWnd=Handle; Icon.uID=(UINT)MYNOTIFYICONID; Icon.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; Icon.uCallbackMessage=MYWM_NOTIFYICON; Icon.hIcon=LoadIcon(HInstance,"MAINICON"); strcpy(Icon.szTip,"Icon"); Shell_NotifyIcon(NIM_ADD,&Icon); ShowWindow(Application->Handle,SW_HIDE); ShowWindow(Handle,SW_HIDE); } //--------------------------------------------------------------------------- void TForm1::HideIcon() { Icon.cbSize=sizeof(NOTIFYICONDATA); Icon.hWnd=Handle; Icon.uID=(UINT)MYNOTIFYICONID; Icon.uFlags=0; Icon.uCallbackMessage=MYWM_NOTIFYICON; Icon.hIcon=0; strcpy(Icon.szTip,"Icon"); Shell_NotifyIcon(NIM_DELETE,&Icon); ShowWindow(Application->Handle,SW_NORMAL); ShowWindow(Handle,SW_NORMAL); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormActivate(TObject *Sender) { ShowIcon(); } //--------------------------------------------------------------------------- void __fastcall TForm1::N2Click(TObject *Sender) { ::ShellExecute(::GetDesktopWindow(),"explore",NULL,NULL,NULL,SW_SHOWNORMAL); } //--------------------------------------------------------------------------- void __fastcall TForm1::N4Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { HideIcon(); } //--------------------------------------------------------------------------- void __fastcall TForm1::N1Click(TObject *Sender) { char WinDir[MAX_PATH]; ::GetWindowsDirectory(WinDir,MAX_PATH); AnsiString sysdir=AnsiString(WinDir)+"\\Notepad.exe"; ::ShellExecute(NULL,"open",sysdir.c_str(),NULL,NULL,SW_SHOWNORMAL); } //--------------------------------------------------------------------------- |
送花文章: 1534,
|
2005-06-21, 05:04 PM | #3 (permalink) |
版區管理員
|
Unit1.h內容
語法:
//--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H #define MYNOTIFYICONID WM_USER+10 #define MYWM_NOTIFYICON WM_USER+20 //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <Menus.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TPopupMenu *PopupMenu1; TMenuItem *N1; TMenuItem *N2; TMenuItem *N3; TMenuItem *N4; void __fastcall FormActivate(TObject *Sender); void __fastcall N2Click(TObject *Sender); void __fastcall N4Click(TObject *Sender); void __fastcall FormClose(TObject *Sender, TCloseAction &Action); void __fastcall N1Click(TObject *Sender); private: // User declarations NOTIFYICONDATA Icon; void TForm1::ShowIcon(); void TForm1::HideIcon(); public: // User declarations __fastcall TForm1(TComponent* Owner); void virtual _fastcall TRAYCALLBACK(TMessage& Message); BEGIN_MESSAGE_MAP MESSAGE_HANDLER(MYWM_NOTIFYICON,TMessage,TRAYCALLBACK) END_MESSAGE_MAP(TForm) }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif |
送花文章: 1534,
|