我在托盘图标出点击右键,就是不出现快捷菜单,一下是我的代码:
procedure TfrmAppMain.WMBarIcon(var Message:TMessage);
var
   lpData:PNotifyIconData;
   P : TPoint;
begin
  if Message.LParam =WM_RBUTTONDOWN then
  begin
        self.PopupMenu:=sysMenu;
        SetForegroundWindow(Handle);
        GetCursorPos(P);
        sysMenu.Popup(P.X,P.Y);
  end;

解决方案 »

  1.   

    const WM_Icon = WM_USER + 100;
    NotifyIcon.cbSize := Sizeof(TNotifyIconData);
      NotifyIcon.Wnd := Handle;
      NotifyIcon.uID := 1;
      NotifyIcon.uFlags := NIF_ICON or NIF_Message or NIF_TIP;
      NotifyIcon.uCallbackMessage := WM_Icon;
      NotifyIcon.hIcon := Application.Icon.Handle;
      NotifyIcon.szTip := '嘿嘿';
      Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
      

  2.   

    这是我以前写的代码
    const
    MYWM_NOTIFYICON = WM_USER + 100;     //托盘栏图标消息
    var
    WM_TASKBARCREATED : LongWord;    //防崩溃消息  protected
    procedure WndProc(var MyMessage: TMessage); override;
    procedure TfMain.WndProc(var MyMessage: TMessage);
    var
    pt: TPoint;
    begin
    case MyMessage.Msg of
      WM_CLOSE:  //关闭事件
      begin
        application.Minimize;
      end;
      WM_CREATE:
      begin
      WM_TASKBARCREATED := RegisterWindowMessage('TaskbarCreated');
      //创建托盘栏图标类
    TrayIcon := TTrayIcon.Create(self);
        TrayIcon.ActiveIcon.Handle := LoadIcon(HInstance, 'Tray0');
        TrayIcon.DeActiveIcon.Handle := LoadIcon(HInstance, 'Tray1');
      end;
      WM_DESTROY: // 窗体销毁消息
      begin
    //释放托盘栏图标
    TrayIcon.NotifyDelete(self.Handle);
       //释放托盘栏图标类
        TrayIcon.Free;
      end;
      WM_SYSCOMMAND: begin
       case MyMessage.WParam of
        SC_MINIMIZE:   // 窗体最小化
         application.Minimize
        else
    inherited;
        end;
      end;
      MYWM_NOTIFYICON:
    case MyMessage.lParam of
    WM_LBUTTONDBLCLK:  //鼠标左键双击
    begin
    if self.Showing = true then
          begin
    application.Minimize;
            self.Hide;
          end
    else
          begin
           self.Show;
           application.Restore;
    SetForegroundWindow(self.Handle);
          end;
    end;
    WM_RBUTTONDOWN:   //鼠标右键被按下
    begin
    GetCursorPos(pt);
    SetForegroundWindow(self.Handle);
        pmTrayIcon.Popup(pt.x,pt.y);
    end
    else
    //调用父类的WndProc方法处理其它消息
    inherited;
    end;
      else
      if MyMessage.Msg = WM_TASKBARCREATED then //托盘栏防崩溃处理
    begin
         TrayIcon.NotifyDelete(self.Handle);
         TrayIcon.NotifyAdd(self.Handle, self.Showing);
      end
        else
    //调用父类的WndProc方法处理其它消息
    inherited;
      end;
    end;