const
WM_TRAYNOTIFY=WM_USER+1;//定义通知消息
procedure TForm1.FormCreate(Sender: TObject);
begin
hs:=LoadIcon(hInstance, 'Icon0');
nd0.cbSize := sizeof(NotifyIconData);
nd0.Wnd := handle;
nd0.uID := 0;
nd0.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
nd0.uCallbackMessage := WM_TRAYNOTIFY;
nd0.hIcon:=image1.Picture.Icon.Handle;
StrPLCopy(nd0.szTip, '医务通软件', 63);
//在任务栏状态区添加图标
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
//将图标从任务栏状态区删除
Shell_NotifyIcon(NIM_DELETE, @nd0);
end;
//处理 通知消息
procedure TForm1.WndProc(var Msg: TMessage);
var
IconID:integer;
pt:TPOINT;
begin
if msg.Msg = WM_TRAYNOTIFY then
begin
{
在通知消息中,wParam参数为图标的uID,
lParam参数为鼠标事件的类型。
}
iconID := msg.WParam;
//获取鼠标的在屏幕上的位置
GetCursorPos(pt);
//通知消息的处理的基本框架结构如下:
case msg.lParam of
WM_LBUTTONDOWN:
begin
//鼠标左键被按下
self.PopupMenu1.Popup((mouse.CursorPos.x-50),(mouse.CursorPos.y-50));
end;
WM_RBUTTONDOWN:
begin
//鼠标右键被按下
end;
WM_LBUTTONUP:
begin
//释放鼠标左键
end;
WM_RBUTTONUP:
begin
//释放鼠标右键
end;
WM_MOUSEMOVE:
begin
//鼠标在图标上移动
end;
WM_LBUTTONDBLCLK:
begin
//鼠标左键双击
end;
WM_RBUTTONDBLCLK:
begin
//鼠标右键双击
end;
end
//end case
end
else//调用父类的WndProc方法处理其它消息
inherited;
end;
procedure TForm1.FormCloseQuery(Sender: TObject
var CanClose: Boolean);
begin
Application.Initialize();
application.ShowMainForm:=false;
ShowWindow(Application.Handle, SW_HIDE);
form1.WindowState:=wsMinimized;
Shell_NotifyIcon(NIM_ADD, @nd0);
application.Run;
end;