J
jacer
Unregistered / Unconfirmed
GUEST, unregistred user!
网上很多关于 TrayIcon 的文章,我 CUT 了一份,可是我的窗口怎么也不到<br>任务栏去,还是赫然一个大 Form,把 Visible 设为 False 也没用。这是<br>什么原因呢?<br>我的代码如下:<br><br>unit TrayIcon;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes,<br> Graphics, Controls, Forms, Dialogs,<br> ShellAPI, StdCtrls;<br><br>{自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息}<br>const MY_MESSAGE = WM_USER + 678;<br><br>type<br> TMyTrayForm = class(TForm)<br> procedure FormCreate(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure FormPaint(Sender: TObject);<br> private<br> procedure OnIconNotify(var Message: TMessage);<br> message MY_MESSAGE;<br> public<br> { Public declarations }<br> end;<br><br>var<br> MyTrayForm: TMyTrayForm;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TMyTrayForm.OnIconNotify(var Message: TMessage);<br>const<br> Busy: Boolean = false;<br>begin<br>... ...<br>end;<br><br>{当主Form建立时通知Windows加入小图标}<br>procedure TMyTrayForm.FormCreate(Sender: TObject);<br>var<br> nid: TNotifyIconData;<br>begin<br> nid.cbSize := sizeof(nid); // nid变量的字节数<br> nid.Wnd := Self.Handle; // 主窗口句柄<br> nid.uID := $DEDB; // 内部标识,可设为任意数<br> nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指定<br> nid.szTip := 'This is a test application'; // 提示字符串<br> nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息<br> nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有效<br> if not Shell_NotifyIcon(NIM_ADD, @nid) then begin<br> ShowMessage('Failed!');<br> Application.Terminate;<br> end;<br> {将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}<br> SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);<br>end;<br><br>procedure TMyTrayForm.FormClose(Sender: TObject; var Action: TCloseAction);<br>var<br> nid: TNotifyIconData;<br>begin<br> nid.cbSize := sizeof(nid);<br> nid.uID := $DEDB; <br> nid.Wnd := Self.Handle;<br> Shell_NotifyIcon(NIM_DELETE, @nid);<br>end;<br><br>procedure TMyTrayForm.FormPaint(Sender: TObject);<br>begin<br> Hide;<br>end;<br><br>end.<br>