我写了一个托盘程序,当右击时弹出快捷菜单,但是怎么样当在屏幕上其它地方点击一下时,怎么把菜单消失,谢谢~

解决方案 »

  1.   

    ' 我用如下方法,解决该问题
    Private Sub tmrSystem_Timer()
      Dim intKey As Integer
      Dim intMouse As Integer
      Dim strClassName As String * 255
      Dim hwnd1 As Long
      Dim Mousemsg As POINTAPI
      
        intMouse = (GetAsyncKeyState(VK_LBUTTON) And &HFF00) / 2 ^ 15
     
      If intKey = -1 Then     'F12
         frmMain.WindowState = frmMain.LastState
         frmMain.Visible = True
         frmMain.SetFocus
      End If
      
      If intMouse = -1 And frmMain.WindowState = 1 Then   'LBUTTON
            GetCursorPos Mousemsg
            Call GetClassName(WindowFromPoint(Mousemsg.X, Mousemsg.Y), strClassName, 255)
            If (InStr(strClassName, "#32768")) < 1 Then
                hwnd1 = FindWindow("#32768", "")
                Dim rt As RECT
                
                If hwnd1 > 0 Then
                   GetWindowRect hwnd1, rt
                   If rt.Left > Screen.Width / Screen.TwipsPerPixelX - 300 And rt.Top > Screen.Height / Screen.TwipsPerPixelY - 150 Then
                     SendMessage hwnd1, &H10, 0, 0   '关闭右键菜单
                   End If
                End If
            End If
      End If
     endif
      

  2.   

    UP,也可用活动窗体啊!
    GetForegroundWindow VB声明 
    Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long 
    说明 
    获得前台窗口的句柄。这里的“前台窗口”是指前台应用程序的活动窗口 
    返回值 
    Long,前台窗口的句柄 
    注解 
    windows nt支持多个桌面,它们相互间是独立的。每个桌面都有自己的前台窗口
     
      

  3.   

    在你调用 PopupMenu的时候 先SetFocus一下窗体
      

  4.   

    在弹出快捷菜单程序前或后加上:
    SetForegroundWindow Me.hwnd    '关键是这个函数,加上它之后,弹出菜单就会消失!!