資源描述:
《delphi托盤窗體編程》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、在Delphi7下要制作系統(tǒng)托盤,只能制作一個比較簡單的系統(tǒng)托盤,因為ShellAPI文件定義的TNotifyIconData結(jié)構(gòu)體是比較早的版本。定義如下:123456789_NOTIFYICONDATAA?=?record???cbSize:?DWORD;???Wnd:?HWND;???uID:?UINT;???uFlags:?UINT;???uCallbackMessage:?UINT;???hIcon:?HICON;???szTip:?array?[0..63]?of?AnsiChar;?end;?下面開始實現(xiàn)下最小化到系統(tǒng)托盤功能:1.新建應(yīng)用程序,然后在“菜單欄”→“Pro
2、ject”→“Options”→”Application“為程序設(shè)定下標(biāo)題和圖標(biāo),一定得設(shè)置圖標(biāo),不讓顯示系統(tǒng)托盤的時候就會空白;2.在窗體上放置一個右鍵菜單,添加兩個菜單項,如下圖所示:3.窗體單元文件代碼如下:unit?Unit1;??interface??uses???Windows,?Messages,?SysUtils,?Variants,?Classes,?Graphics,?Controls,?Forms,???Dialogs,?ShellAPI,?Menus;??const???WM_TRAYMSG?=?WM_USER?+?101;???????????????????
3、//自定義托盤消息?type???TForm1?=?class(TForm)?????pm1:?TPopupMenu;?????mniN1:?TMenuItem;?????mniwo1:?TMenuItem;?????procedure01020304050607080910111213141516171819202122232425262?FormCreate(Sender:?TObject);?????procedure?FormDestroy(Sender:?TObject);?????procedure?mniN1Click(Sender:?TObject);???privat
4、e?????procedure?WMTrayMsg(var?Msg:?TMessage);message?WM_TRAYMSG;????//聲明托盤消息?????procedure?WMSysCommand(var?Msg:?TMessage);message?WM_SYSCOMMAND;???public?????{?Public?declarations?}???end;??var???Form1:?TForm1;???NotifyIcon:?TNotifyIconData;????????????????????//定義托盤圖標(biāo)結(jié)構(gòu)體?implementation??{$R?*.
5、dfm}?{-------------------------------------------------------------------------------??Description:?窗體創(chuàng)建時,即創(chuàng)建托盤?-------------------------------------------------------------------------------}?procedure?TForm1.FormCreate(Sender:?TObject);?begin???with?NotifyIcon?do???begin?????cbSize?:=?SizeOf(T
6、NotifyIconData);?????Wnd?:=?Self.Handle;?????uID?:=?1;?????uFlags?:=?NIF_ICON?+?NIF_MESSAGE?+?NIF_TIP;???//圖標(biāo)、消息、提示信息?????uCallbackMessage?:=?WM_TRAYMSG;?????hIcon?:=?Application.Icon.Handle;?????szTip?:=?'托盤測試';???end;???Shell_NotifyIcon(NIM_ADD,@NotifyIcon);?end;?{-----------------------------
7、--------------------------------------------------??Description:?窗體銷毀時,卸載托盤?-------------------------------------------------------------------------------}?procedure?TForm1.FormDestroy(Sender:?TObject);?begin???Shell_Notify