我这个程序在任务条加入图标后无法删除,请大家看看。(100分)

  • 主题发起人 主题发起人 davidyuan
  • 开始时间 开始时间
D

davidyuan

Unregistered / Unconfirmed
GUEST, unregistred user!
在WIN2000环境下,图标无法直接删除,直到鼠标放到上面后才删除。<br><br><br>unit Unit4;<br><br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ShellAPI;<br><br>const MY_MESSAGE = WM_USER + 100;<br>type<br>&nbsp; TForm4 = class(TForm)<br>&nbsp; &nbsp; procedure FormPaint(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; &nbsp; &nbsp; procedure OnIconNotify(var Message: TMessage);message MY_MESSAGE;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form4: TForm4;<br><br>implementation<br>&nbsp;uses &nbsp; Unit2 &nbsp;{Form2},unit1;<br>{$R *.DFM}<br><br>procedure TForm4.FormPaint(Sender: TObject);<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; 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>&nbsp; &nbsp; &nbsp; &nbsp; form1.timer3.enabled:=false;<br>&nbsp; &nbsp; &nbsp; &nbsp; form1.timer2.enabled:=false;<br>&nbsp; &nbsp; &nbsp; &nbsp; form2.show;<br>&nbsp; &nbsp; &nbsp; &nbsp; form1.timer1.Interval :=1000;<br>&nbsp; &nbsp; &nbsp; &nbsp; 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>&nbsp; &nbsp; &nbsp; &nbsp; nid.cbSize := sizeof(nid); // nid变量的字节数<br>&nbsp; &nbsp; &nbsp; &nbsp; nid.uID := 1234; //内部标识,与加入小图标时的数一致<br>&nbsp; &nbsp; &nbsp; &nbsp; nid.Wnd := Handle; //主窗口句柄<br>&nbsp; &nbsp; &nbsp; &nbsp; Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标<br>&nbsp; &nbsp; &nbsp; &nbsp; 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>&nbsp; &nbsp; &nbsp; &nbsp; nid.cbSize := sizeof(nid); // nid变量的字节数<br><br>&nbsp; &nbsp; &nbsp; &nbsp; nid.Wnd := Handle; // 主窗口句柄<br><br>&nbsp; &nbsp; &nbsp; &nbsp; nid.uID := 1234; // 内部标识,可设为任意数<br><br>&nbsp; &nbsp; &nbsp; &nbsp; nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指定<br><br>&nbsp; &nbsp; &nbsp; &nbsp; nid.szTip := 'DDDVideo v1.0'; // 提示字符串<br><br>&nbsp; &nbsp; &nbsp; &nbsp; nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息<br><br>&nbsp; &nbsp; &nbsp; &nbsp; nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有效<br><br>&nbsp; &nbsp; &nbsp; &nbsp; if not Shell_NotifyIcon(NIM_ADD, @nid) then begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('Failed!');<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.Terminate;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}<br><br>&nbsp; &nbsp; &nbsp; &nbsp; SetWindowLong(form4.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);<br><br>end;<br>end.
 
其实在WIN98里也常常可以遇见这样的问题,我曾经做过一个全屏幕看图的东西,<br>在退出程序的时候常常可以看到在任务栏上有一个“剩余”的东东,据说这是因为WIN98在<br>窗体被释放以后,桌面没有刷新的缘故。。。。。。。。。。
 
我已经知道了,这是需要将FORMCLOSE 的内容写到FORCLOSEQUERY内就行了
 
End it,please!
 
davidyuan: &nbsp;你好! 我在Win2000下做了试验,图标可以删除的 。代码如下:<br>var<br>&nbsp; NdICO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:NOTIFYICONDATA ;<br><br>procedure TfrmLogin.FormCreate(Sender: TObject);<br>begin<br>&nbsp; selfIp := getComputerIP;<br>&nbsp; TestPort;<br>&nbsp; NdICO.cbSize := sizeof(NOTIFYIConDATA);<br>&nbsp; NdIco.Wnd := Self.Handle;<br>&nbsp; NdIco.uID := 1;<br>&nbsp; NdIco.uFlags :=NIF_ICON + NIF_TIP;<br>&nbsp; NdIco.hIcon := LoadICOn(hInstance, 'MYICON');<br>&nbsp; shell_NotifyIcon(NIM_ADD,@NdIco);<br>end;<br>{ delete icon }<br>procedure TfrmLogin.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; shell_NotifyIcon(NIM_Delete,@ndico);<br>end;<br><br>程序结束后,图标自然就不见呢! &nbsp;:)))<br>
 
就是,放到destory里
 
davidyuan兄: 对不起哈! 我忘了一条。你一定要在窗体的资源加载时加上下面这句哈<br><br>implementation<br><br>{$R *.dfm}<br>{$R ResIcon.res} &nbsp;// 这句一定要加哈!ResIcon.res 是你用图标编辑器编辑的.res文件哈<br>而且ResIcon.res 要在你程序的运行目录下哈!
 
我用SetWindowLong(form4.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);时<br>若任务栏设为隐藏,FORM可以在左下方可见,若不隐藏则不可见了。弄不明白。<br>
 
太好了,我找了很久
 
后退
顶部