源代码如下:
procedure TForm1.WMSysCommand(var Msg:TWMSysCommand);
begin
if(Msg.CmdType=SC_MINIMIZE) then
begin
Form1.Hide;
with MyNotifyStruct do
begin
cbSize:=sizeof(MyNotifyStruct);
Wnd:=Handle;
uID:=1;
uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE;
uCallBackMessage:=MI_ICONEVENT;
hIcon:=Application.Icon.Handle;
szTip:='系统托盘程序';
end;
Shell_NotifyIcon(NIM_ADD,@MyNotifyStruct);
ShowWindow(Application.Handle,SW_HIDE);
end;
if(Msg.CmdType=SC_CLOSE) then
//showwindow(application.Handle,SW_Maximize);
begin
Form1.Hide;
with MyNotifyStruct do
begin
cbSize:=sizeof(MyNotifyStruct);
Wnd:=Handle;
uID:=1;
uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE;
uCallBackMessage:=MI_ICONEVENT;
hIcon:=Application.Icon.Handle;
szTip:='系统托盘程序';
end;
Shell_NotifyIcon(NIM_ADD,@MyNotifyStruct);
ShowWindow(Application.Handle,SW_HIDE);
end;
if(Msg.CmdType=SC_MAXIMIZE) then
form1.windowstate:=wsMaximized;
if(Msg.CmdType=SC_RESTORE) then
begin
showwindow(application.Handle,SW_SHOWNORMAL);
form1.WindowState:=wsNormal;
end;
end;
procedure TForm1.WMSysCommand(var Msg:TWMSysCommand);
begin
if(Msg.CmdType=SC_MINIMIZE) then
begin
Form1.Hide;
with MyNotifyStruct do
begin
cbSize:=sizeof(MyNotifyStruct);
Wnd:=Handle;
uID:=1;
uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE;
uCallBackMessage:=MI_ICONEVENT;
hIcon:=Application.Icon.Handle;
szTip:='系统托盘程序';
end;
Shell_NotifyIcon(NIM_ADD,@MyNotifyStruct);
ShowWindow(Application.Handle,SW_HIDE);
end;
if(Msg.CmdType=SC_CLOSE) then
//showwindow(application.Handle,SW_Maximize);
begin
Form1.Hide;
with MyNotifyStruct do
begin
cbSize:=sizeof(MyNotifyStruct);
Wnd:=Handle;
uID:=1;
uFlags:=NIF_ICON or NIF_TIP or NIF_MESSAGE;
uCallBackMessage:=MI_ICONEVENT;
hIcon:=Application.Icon.Handle;
szTip:='系统托盘程序';
end;
Shell_NotifyIcon(NIM_ADD,@MyNotifyStruct);
ShowWindow(Application.Handle,SW_HIDE);
end;
if(Msg.CmdType=SC_MAXIMIZE) then
form1.windowstate:=wsMaximized;
if(Msg.CmdType=SC_RESTORE) then
begin
showwindow(application.Handle,SW_SHOWNORMAL);
form1.WindowState:=wsNormal;
end;
end;
begin
inherited;
{...你的代码}
end;
var
p:TPoint;
begin
case Msg.Msg of
WM_USER+1:
case Msg.LParam of
WM_LBUTTONDBLCLK:
begin
MainF.Show;
ShowWindow(Application.Handle, SW_SHOW);
end;
WM_RBUTTONDOWN:
begin
//以下三句:当popmenu弹出鼠标却单击在空白处时,使弹出菜单消失
SetForegroundWindow(Application.Handle);
Application.BringToFront;
Application.ProcessMessages;
//以上三句:当popmenu弹出鼠标却单击在空白处时,使弹出菜单消失
GetCursorPos(p);
Popupmenu1.Popup(p.X,p.Y);
end;
end;
end;
inherited;
end;