procedure TForm1.FormCreate(Sender: TObject);
begin
FIcon:=TIcon.Create ;
FIcon.Handle :=Application.Icon.Handle ;
{if Ficon.Handle =0 then
begin
MessageDlg('Don''t open the Icon!',mtError,[mbOK],0);
Application.Terminate ;
Exit;
end;
with nid do
begin
cbSize:=sizeof(nid);
Wnd:=Handle;
uId:=TRAYICONID;
uFlags:=NIF_MESSAGE+NIF_ICON+NIF_TIP;
StrPCopy(nid.szTip,Application.Title );
uCallBackMessage:= CM_TRAYICON; //WM_USER+1;
hIcon:=FIcon.Handle ;
Shell_NotifyIcon(NIM_ADD,@nid);
end;}
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_DELETE,@nid);
FIcon.Free ;
end;
procedure TForm1.MessageHandle(var Msg:TMessage);
var
Point:TPoint;
begin
case Msg.Msg of
CM_TRAYICON:
case Msg.LParam of
WM_LBUTTONDBLCLK:
begin
if Visible then
hide
else
show;
end;
WM_RBUTTONUP:
begin
GetCursorPos(Point);
PopupMenu1.Popup(Point.x,Point.y);
end;
end;
end;
end;
procedure TForm1.exit1Click(Sender: TObject);
begin
close;
end;
procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);
begin
if Ficon.Handle =0 then
begin
MessageDlg('Don''t open the Icon!',mtError,[mbOK],0);
Application.Terminate ;
Exit;
end;
with nid do
begin
cbSize:=sizeof(nid);
Wnd:=Handle;
uId:=TRAYICONID;
uFlags:=NIF_MESSAGE+NIF_ICON+NIF_TIP;
StrPCopy(nid.szTip,Application.Title );
uCallBackMessage:= CM_TRAYICON;
hIcon:=FIcon.Handle ;
Shell_NotifyIcon(NIM_ADD,@nid);
end;