我在delphi下调用了vc的exe,vc的exe启动后在系统托盘处(屏幕右下)显示一图标,
当我在delphi下退出vc的exe(结束进程后),vc的系统托盘图标并不消失,只有
用鼠标在系统托盘处移动才会消失。----怎么解决这个问题呢?请高手帮忙谢谢!
当我在delphi下退出vc的exe(结束进程后),vc的系统托盘图标并不消失,只有
用鼠标在系统托盘处移动才会消失。----怎么解决这个问题呢?请高手帮忙谢谢!
TnotifyIconDataA = record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
szTip: ARRAY[0..63] of AnsiChar;
end; dwMessage取值为:
NIM_ADD 增加一个新图标
NIM_MODIFY 修改一个已有的图标
NIM_DELETE 删除一个已有的图标
实现一个Delphi中实现系统状态栏图标的窗体步骤如下:
1)创建一个应用程序
2)在主窗体上加一个TButton组件、一个TImage组件和一个TPopupMenu组件
3)编写主窗体的mymessaage消息处理函数,此函数说明在图标上用鼠标右键单击时会弹出一个菜单
4)编写TButton组件的OnClick事件及菜单项的OnClick事件
5)程序源代码如下所示:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ImgList, StdCtrls, ShellAPI, ExtCtrls;const
mymsg = wm_user + 1;
iid = 100;type
TForm1 = class(TForm)
Button1: TButton;
PopupMenu1: TPopupMenu;
a11: TMenuItem;
b11: TMenuItem;
c11: TMenuItem;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure c11Click(Sender: TObject);
procedure a11Click(Sender: TObject);
private
{ Private declarations }
procedure mymessage(var message:tmessage);
message mymsg;
public
{ Public declarations }
end;var
Form1: TForm1;
ntid: TnotifyIconDataA;implementation{$R *.dfm}//隐藏窗口,在托盘上显示图标
procedure TForm1.Button1Click(Sender: TObject);
begin
ntid.cbsize := sizeof(TnotifyIconDataA);
ntid.Wnd := Handle;
ntid.uID := iid;
ntid.uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
ntid.uCallbackMessage := mymsg;
ntid.hIcon := image1.Picture.Icon.Handle;
ntid.szTip := 'asdf';
shell_notifyicona(NIM_ADD,@ntid); self.Visible := false;
end;//处理鼠标右键,弹出菜单
procedure TForm1.mymessage(var message:tmessage );
var
mypt:Tpoint;
begin
Inherited;
if message.LParam = WM_RBUTTONUP then
begin
getCursorPos(mypt);
PopupMenu1.Popup(mypt.X, mypt.Y);
end;
message.rResult := 0;
end;procedure TForm1.c11Click(Sender: TObject);
begin
close;
end;//还原窗口,托盘图标消失
procedure TForm1.a11Click(Sender: TObject);
begin
ntid.cbSize := sizeof(TnotifyIconDataA);
ntid.Wnd := Handle;
ntid.uID := iid;
ntid.uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
ntid.uCallbackMessage := mymsg;
ntid.hIcon := image1.Picture.Icon.Handle;
ntid.szTip := 'asdf';
shell_notifyicona(NIM_DELETE,@ntid);
self.Visible := true;
end;end.