procedure TForm2.FormCreate(Sender: TObject);
Begin
//NotifyIcon为全局变量,在程序的开头已经定义了
with NotifyIcon do
begin
cbSize:=SizeOf(TNotifyIconData);
Wnd:=Handle; //指向当前窗体Form1的句柄
uID:=1;
uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
uCallBackMessage:=WM_NID;
hIcon:=Application.Icon.Handle;
szTip:='张家恶少';
end;
//把设置好的变量NotifyIcon加入到系统中以便处理
Shell_NotifyIcon(NIM_ADD,@NotifyIcon);
End;
procedure tform2.WMNID(var msg:TMessage);
begin
case msg.LParam of
WM_LBUTTONUp:Form2.Visible:=not Form2.Visible;
//WM_RBUTTONUP: ShowMessage('您点击的是右键');
WM_RBUTTONUP:
begin
PopupMenu1.Popup(mouse.CursorPos.X,mouse.CursorPos.Y);
end;
End;
End;
procedure TForm1.OnIconNotify(var Message: TMessage);
var
Busy: Boolean;
begin
Busy:=False;
if not Busy then
begin
Busy := true;
if Message.LParam=WM_LBUTTONDOWN then
begin
if Application.MessageBox('Are you sure','Exit', MB_YESNO)=IDYES then
show;
end;
end;
Busy := false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
AddSystray(handle);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DelSystray(handle);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
hide;
end;