procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMinimize :=DoMin;
end;
procedure TForm1.DoMin(Sender:TObject);
var NT:TNotifyIconData;
begin
with NT do
begin
cbSize:=SizeOf(TNotifyIconData);
Wnd:=Handle;
UID:=MY_TRAY_ICON;
uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
uCallBackMessage:=WM_TRAYNOTIFY;
hIcon:=LoadIcon(hInstance,'CDROM');// 此处需要修改;
szTip:='我的程序'#0;
end;
Shell_NotifyIcon(NIM_ADD,@NT);
ShowWindow(Application.Handle,SW_HIDE);
Application.Minimize;
end;
procedure TForm1.WMTrayNotify(var Msg:TMessage);
var NT:TNotifyIconData;
P:TPoint;
begin
GetCursorPos(P);
if (Msg.LParam=WM_RBUTTONUP) then PopupMenu1.Popup(p.x,p.y);
if (Msg.lParam<>WM_LBUTTONUP) then exit;
with NT do
begin
cbSize:=SizeOf(TNotifyIconData);
Wnd:=Handle;
UID:=MY_TRAY_ICON;
uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
uCallBackMessage:=WM_TRAYNOTIFY;
hIcon:=LoadIcon(hInstance,'CDROM');// 此处需要修改;
szTip:=#0;
end;
Shell_NotifyIcon(NIM_DELETE,@NT);
ShowWindow(Application.Handle,SW_SHOW);
Application.Restore;
end;