1、new -->application
2、在form1中加入一个tPopMenu 命名为pm1
3、uses ShellAPI;
4、定义一个常量在
const
WM_TRAYMSG = WM_USER + 101;
5、在private中生命变量
NotifyIcon: TNotifyIconData;
6.声明两个消息
procedure TfrmMain.WMSysCommand(var Msg: TMessage);
begin
if Msg.WParam = SC_ICON then
Self.Visible := False
else
DefWindowProc(Self.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
end;
procedure TfrmMain.WMTrayMsg(var Msg: TMessage);//声明托盘消息
var
p: TPoint;
begin
case Msg.LParam of
WM_LBUTTONDOWN: Self.Visible := True; //显示窗体
WM_RBUTTONDOWN:
begin
SetForegroundWindow(Self.Handle); //把窗口提前
GetCursorPos(p);
pm1.Popup(p.X, p.Y);
end;
end;
end;
7、oncreate中
with NotifyIcon do
begin
cbSize := SizeOf(TNotifyIconData);
Wnd := Self.Handle;
uID := ;
uFlags := NIF_ICON + NIF_MESSAGE + NIF_TIP; //图标、消息、提示信息
uCallbackMessage := WM_TRAYMSG;
hIcon := Application.Icon.Handle;
szTip := 'erp服务';
end;
Shell_No