在托盘图标上点击右键谈出菜单,但是当我点击其他地方的时候,该菜单不能消失,怎么让他消失呢?

解决方案 »

  1.   

    在你弹出菜单的代码前面加上以下这句就行了:
    SetForegroundWindow(Self.Handle);
    PopupMenu.Popup(......);    //你的弹出菜单代码
      

  2.   

    procedure TMainForm.MyTrayMessage(var message: Tmessage);
    var //托盘消息处理事件
      CursorPos : TPoint;
    begin
      //在这里处理用户点击托盘图标事件,可以根据WM_MOUSEMOVE消息的不同情况产生不同的回应,例如区别对待单击和双击等等
      case message.lParam of
      WM_RBUTTONDOWN :
      begin
        GetCursorPos(CursorPos);
        SetForegroundWindow(handle);
        
        Application.ProcessMessages;
        
        TrayPopMenu.Popup( CursorPos.x ,CursorPos.y );
        PostMessage(Application.MainForm.Handle, WM_NULL, 0, 0);
      end;
      end;end;