private
procedure WMSYSCOMMAND(var msg: TWMSYSCOMMAND); message WM_SYSCOMMAND;
procedure AddTray;
procedure RemoveTray;
public
end;
var
Form1 : TForm1;
implementation
{$R *.DFM}
//uses ShellApi
//增加小图标
procedure TForm1.AddTray;
var
Nid : TNotifyIconData;
begin
FillChar(Nid, SizeOf(TNotifyIconData), 0);
Nid.cbSize := SizeOf(TNotifyIconData);
Nid.Wnd := Handle; //窗口句柄
Nid.uID := 1; //内部标识,可任意指定
Nid.hIcon := Application.Icon.Handle; //要加入的图标句柄
Nid.szTip := '图标示例程序'; //提示字符串
Nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; //指明哪些字段有效
if not Shell_NotifyIcon(NIM_ADD, @nid) then
Application.Terminate;
end;
//去除小图标
procedure TForm1.RemoveTray;
var
Nid : TNotifyIconData;
begin
FillChar(Nid, SizeOf(TNotifyIconData), 0);
Nid.cbSize := SizeOf(TNotifyIconData);
Nid.uID := 1; //内部标识,与加入小图标时的数一致
Nid.Wnd := Handle; //窗口句柄
Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
end;
procedure TForm1.WMSYSCOMMAND(var msg: TWMSYSCOMMAND);
begin
if msg.CmdType = SC_MINIMIZE then
AddTray //增加图标
else
RemoveTray;
inherited;
end;
我没有捕捉到窗体恢复的事件,你自己改一下