uses
...,ShellAPI.
const WM_NOTIFYICON=WM_USER+1;
implementation
type
TMainForm = class(TForm)
......
private
IconData:TNotifyIconData;
procedure AddIcon;
procedure RemoveIcon;
procedure windowhide;
procedure windowshow;
procedure OnNotifyicon(var Message:Tmessage);Message WM_NOTIFYICON;
procedure TMainForm.OnNotifyicon(var Message: Tmessage);
var
mypoint:Tpoint;
begin
if Message.LParam = WM_RBUTTONDOWN then
begin
GetCursorPos(mypoint);
setforegroundwindow(application.Handle);
application.ProcessMessages;
PopupMenuTry.popup(mypoint.x,mypoint.y);
end
else if Message.LParam = WM_LBUTTONDBLCLK THEN
Begin
WindowShow;
end;
end;
procedure TMainForm.windowshow;
begin
self.Show;
self.WindowState:=wsNormal;
Application.ShowHint := True;
self.RemoveIcon;
end;
procedure TMainForm.windowhide;
begin
self.WindowState:=wsMinimized;
self.Hide;
Application.HideHint;
self.addicon;
end;
procedure TMainForm.RemoveIcon;
begin
shell_notifyicon(NIM_DELETE,@ICONDATA);
end;
procedure TMainForm.AddIcon;
begin
IconData.cbSize:=sizeof(IconData);
IconData.Wnd:=handle;
IconData.uID:=1000;
IconData.uFlags:=NIF_MESSAGE+NIF_ICON+NIF_TIP;
IconData.uCallbackMessage:=WM_USER+1;
IconData.hIcon:=application.icon.Handle;
IconData.szTip:='Happy';
Shell_NotifyIcon(NIM_ADD,@IconData);
end;