procedure TForm1.WMMyTrayIconCallBack(var Msg: TMessage);
//处理点击托盘图标的事件,根据 WM_MOUSEMOVE 消息的不同情况产生不同的回应
var
CursorPos : TPoint;
begin
TrayBarPopMenu.AutoPopup:=False;
case Msg.lParam of
//左键按下
WM_LBUTTONDOWN : begin
application.MainForm.BringToFront; //窗体置前
end;
//左键双击
WM_LBUTTONDBLCLK : begin //窗体隐含或显示
Application.MainForm.Visible := not Application.MainForm.Visible;
SetForegroundWindow(Application.Handle);
end;
//右键按下
WM_RBUTTONDOWN : begin //显示弹出菜单
GetCursorPos(CursorPos);
TrayBarPopMenu.Popup(CursorPos.x,CursorPos.y);
end;
end//case
end;
procedure TForm1.n_MainFromDispOrHideClick(Sender: TObject);
begin
if Application.MainForm.Visible then
begin
if FormStep1.Showing Then FormStep1.Hide;
if FormStep2.Showing Then FormStep2.Hide;
Application.MainForm.Hide;
n_MainFromDispOrHide.Caption :='显示主窗体';
end
else
begin
Application.MainForm.Show;
n_MainFromDispOrHide.Caption :='隐藏主窗体';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);//程序不在任务栏上显示
TrayShow(Application.MainForm);//显示图标
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Shell_NotifyIcon(NIM_DELETE, @MyTrayIcon);//删除托盘图标
end;