D
davidyuan
Unregistered / Unconfirmed
GUEST, unregistred user!
在WIN2000环境下,图标无法直接删除,直到鼠标放到上面后才删除。<br><br><br>unit Unit4;<br><br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ShellAPI;<br><br>const MY_MESSAGE = WM_USER + 100;<br>type<br> TForm4 = class(TForm)<br> procedure FormPaint(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br> procedure OnIconNotify(var Message: TMessage);message MY_MESSAGE;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form4: TForm4;<br><br>implementation<br> uses Unit2 {Form2},unit1;<br>{$R *.DFM}<br><br>procedure TForm4.FormPaint(Sender: TObject);<br>begin<br> Hide;<br><br>end;<br>procedure TForm4.OnIconNotify(var Message: TMessage);<br><br>const<br><br>Busy: Boolean = false;<br><br>begin<br><br>if not Busy then begin<br><br>Busy := true;<br><br>if Message.LParam=WM_LBUTTONDOWN then<br>begin<br> form1.timer3.enabled:=false;<br> form1.timer2.enabled:=false;<br> form2.show;<br> form1.timer1.Interval :=1000;<br> form1.timer1.Enabled :=false;<br><br>end;<br>Busy := false;<br><br>end;<br><br>end;<br><br>procedure TForm4.FormClose(Sender: TObject; var Action: TCloseAction);<br>var<br><br>nid: TNotifyIconData;<br>i:integer;<br>begin<br> nid.cbSize := sizeof(nid); // nid变量的字节数<br> nid.uID := 1234; //内部标识,与加入小图标时的数一致<br> nid.Wnd := Handle; //主窗口句柄<br> Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标<br> Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标<br><br>end;<br><br>procedure TForm4.FormCreate(Sender: TObject);<br>var<br><br>nid: TNotifyIconData;<br><br>begin<br><br> nid.cbSize := sizeof(nid); // nid变量的字节数<br><br> nid.Wnd := Handle; // 主窗口句柄<br><br> nid.uID := 1234; // 内部标识,可设为任意数<br><br> nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指定<br><br> nid.szTip := 'DDDVideo v1.0'; // 提示字符串<br><br> nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息<br><br> nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有效<br><br> if not Shell_NotifyIcon(NIM_ADD, @nid) then begin<br><br> ShowMessage('Failed!');<br><br> Application.Terminate;<br><br> end;<br><br>{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}<br><br> SetWindowLong(form4.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);<br><br>end;<br>end.