一段托盘程序的代码,程序退出后,托盘区的图标不能及时消失,大家来看看什么问题
托盘区的图标不能及时消失,把鼠标放上去,托盘图标才消失。
//托盘源码
unit Utuopan;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus,shellapi;
const
WM_TRAYNOTIFY=2000;
MY_TRAY_ICON=1000;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
N2: TMenuItem;
procedure N2Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure OnMin(Sender: TObject);
procedure WMTrayNotify(var Msg : TMessage);Message WM_TRAYNOTIFY;
end;
var
form1: Tform1;
nid:TNOTIFYICONDATA;
implementation
{$R *.dfm}
procedure TForm1.N2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@nid);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMinimize:=OnMin;
end;
procedure Tform1.OnMin(Sender: TObject);
begin
nid.cbSize:=Sizeof(TNOTIFYICONDATA);
nid.Wnd:=Handle;
nid.uID:=MY_TRAY_ICON;
nid.uFlags:=NIF_TIP OR NIF_ICON OR NIF_MESSAGE;
nid.hIcon:=Application.Icon.Handle;
nid.szTip:='我的程序';
nid.uCallbackMessage:=WM_TRAYNOTIFY;
Shell_NotifyIcon(NIM_ADD,@nid);
ShowWindow(Application.Handle,SW_HIDE);
end;
procedure Tform1.WMTrayNotify(var Msg: TMessage);
var
p:TPoint;
begin
if Msg.LParam=WM_LBUTTONDBLCLK then
begin
nid.cbSize:=Sizeof(TNOTIFYICONDATA);
nid.Wnd:=Application.Handle;
nid.uID:=MY_TRAY_ICON;
nid.uFlags:=NIF_TIP OR NIF_ICON OR NIF_MESSAGE;
nid.uCallbackMessage:=WM_TRAYNOTIFY;
nid.szTip:='';
//Shell_NotifyIcon(NIM_ADD,@nid);
ShowWindow(Application.Handle,SW_SHOW);
Application.Restore;
end
else if Msg.LParam=WM_RBUTTONUP then
begin
GetCursorpos(p);
PopupMenu1.Popup (p.x,p.y);
end;
end;
end.
//托盘源码
unit Utuopan;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus,shellapi;
const
WM_TRAYNOTIFY=2000;
MY_TRAY_ICON=1000;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
N2: TMenuItem;
procedure N2Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure OnMin(Sender: TObject);
procedure WMTrayNotify(var Msg : TMessage);Message WM_TRAYNOTIFY;
end;
var
form1: Tform1;
nid:TNOTIFYICONDATA;
implementation
{$R *.dfm}
procedure TForm1.N2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@nid);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMinimize:=OnMin;
end;
procedure Tform1.OnMin(Sender: TObject);
begin
nid.cbSize:=Sizeof(TNOTIFYICONDATA);
nid.Wnd:=Handle;
nid.uID:=MY_TRAY_ICON;
nid.uFlags:=NIF_TIP OR NIF_ICON OR NIF_MESSAGE;
nid.hIcon:=Application.Icon.Handle;
nid.szTip:='我的程序';
nid.uCallbackMessage:=WM_TRAYNOTIFY;
Shell_NotifyIcon(NIM_ADD,@nid);
ShowWindow(Application.Handle,SW_HIDE);
end;
procedure Tform1.WMTrayNotify(var Msg: TMessage);
var
p:TPoint;
begin
if Msg.LParam=WM_LBUTTONDBLCLK then
begin
nid.cbSize:=Sizeof(TNOTIFYICONDATA);
nid.Wnd:=Application.Handle;
nid.uID:=MY_TRAY_ICON;
nid.uFlags:=NIF_TIP OR NIF_ICON OR NIF_MESSAGE;
nid.uCallbackMessage:=WM_TRAYNOTIFY;
nid.szTip:='';
//Shell_NotifyIcon(NIM_ADD,@nid);
ShowWindow(Application.Handle,SW_SHOW);
Application.Restore;
end
else if Msg.LParam=WM_RBUTTONUP then
begin
GetCursorpos(p);
PopupMenu1.Popup (p.x,p.y);
end;
end;
end.
...全文
相关推荐
PSD AI EPS 缩略图显示插件
PSD AI EPS 缩略图显示插件 Windows7,Windows10 可使用。
Windows 显示TGA DDS 文件 缩略图
安装以后可以直接显示tga, dds 文件类型的缩略图。 Windows 10 操作系统亲测可用。 装了后,重启试下。
最好的DDS、PSD、TGA缩略图预览插件
最好的DDS、PSD、TGA缩略图预览插件,支持常见的格式预览及转换
PSD 缩略图 补丁 Photoshop 2022 win11
PSD 缩略图 补丁 Photoshop 2022 win11
psd 文件缩略图方式查看显示补丁.zip
psd 文件缩略图方式查看显示补丁.zip 解压后,直接运行。


