道先声明了消息处理过程:
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

解决方案 »

  1.   

    procedure TForm1.WMTrayNotify(var Msg: TMessage);
    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;编译时没有问题。
      

  2.   

    const
      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;
      

  3.   


    楼上的对了,应当用Form的Handle,我用成Application的了,(因为消息响应是Form来接收处理的)就是这个原因了,多谢。