道先声明了消息处理过程:
procedure WMTrayNotify(var Msg: TMessage); message WM_TRAYNOTIFY;然后用下面的程序将程序放到系统托盘:
procedure TForm1.ToolButton5Click(Sender: TObject);
begin
nid.cbSize:=sizeOf(TNOTIFYICONDATA);
nid.Wnd:=Application.Handle;
nid.uID:=AREFRESH_TRAY_ICON;
nid.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
nid.uCallbackMessage:=WM_TRAYNOTIFY;
nid.hicon:=Application.Icon.Handle;
nid.szTip:='Project1';
ShowWindow(Handle,SW_HIDE);
ShowWindow(Application.Handle,SW_HIDE);
Shell_NotifyIcon(NIM_ADD,@nid);
end;但是无论我对着托盘中的图标如何点鼠标,下面的程序根本没有响应,是什么问题?
procedure TForm1.WMTrayNotify(var Msg: TMessage);
begin
showMessage('OK');
if (Msg.LParam=WM_LBUTTONDOWN) Then
procedure WMTrayNotify(var Msg: TMessage); message WM_TRAYNOTIFY;然后用下面的程序将程序放到系统托盘:
procedure TForm1.ToolButton5Click(Sender: TObject);
begin
nid.cbSize:=sizeOf(TNOTIFYICONDATA);
nid.Wnd:=Application.Handle;
nid.uID:=AREFRESH_TRAY_ICON;
nid.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
nid.uCallbackMessage:=WM_TRAYNOTIFY;
nid.hicon:=Application.Icon.Handle;
nid.szTip:='Project1';
ShowWindow(Handle,SW_HIDE);
ShowWindow(Application.Handle,SW_HIDE);
Shell_NotifyIcon(NIM_ADD,@nid);
end;但是无论我对着托盘中的图标如何点鼠标,下面的程序根本没有响应,是什么问题?
procedure TForm1.WMTrayNotify(var Msg: TMessage);
begin
showMessage('OK');
if (Msg.LParam=WM_LBUTTONDOWN) Then
解决方案 »
- 关于SQL统计查询语句
- 求助stringGrid使用和窗体停靠的问题
- 繁简体转换
- MDI窗体前加了用于normal类的登录窗体后,再也不能创建子窗体了,是何道理?
- 触发器的问题
- 迷失了方向
- 为什么我插入数据时老是显示“fields xxx can not modified”?我的xxx字段类型为numeric
- 用CCproxy作代理,客户端ftp下载不好用,http的好用 在flashget和ccproxy中怎样设置???
- sos:如何在windows中使不带中文字库的票据打印机打印中文?
- 我们到底选择什么?
- 在DELPHI中调用VC写的DLL
- 我想将str中的涉及到inf中的字串,用upmsg中对应的字串来替换掉?
begin
showMessage('OK');
if (Msg.LParam=WM_LBUTTONDOWN) Then
begin
ShowWindow(Application.Handle,SW_SHOW);
Application.Restore;
SetForegroundWindow(GetLastActivePopup(self.Handle));
Shell_NotifyIcon(NIM_DELETE,@nid);
end;
end;编译时没有问题。
WM_TRAYNOTIFY = WM_USER + 100;procedure WMTrayNotify(var Msg: TMessage); message WM_TRAYNOTIFY;
procedure TForm1.Button1Click(Sender: TObject);
var
nid : TNOTIFYICONDATA;
begin
nid.cbSize:=sizeOf(TNOTIFYICONDATA);
nid.Wnd:=Handle; // 是 form 的 handle。
nid.uID := 0;
nid.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
nid.uCallbackMessage:=WM_TRAYNOTIFY;
nid.hicon:=Application.Icon.Handle;
nid.szTip:='Project1';
ShowWindow(Handle,SW_HIDE);
ShowWindow(Application.Handle,SW_HIDE);
Shell_NotifyIcon(NIM_ADD,@nid);
end;procedure TForm1.WMTrayNotify(var Msg: TMessage);
begin
if (Msg.LParam=WM_LBUTTONDOWN) Then
begin
ShowWindow(Application.Handle, SW_SHOW);
ShowWindow(Handle, SW_SHOW);
Application.Restore;
SetForegroundWindow(GetLastActivePopup(self.Handle));
Shell_NotifyIcon(NIM_DELETE,@nid);
end;
end;
楼上的对了,应当用Form的Handle,我用成Application的了,(因为消息响应是Form来接收处理的)就是这个原因了,多谢。