程序最小化后进入托盘,可发现右键菜单必须选择以后才可以,不能通过点击其他位置而取消右键菜单,望告知,另外问一下怎样通过按关闭按钮实现最小化?谢谢

解决方案 »

  1.   

    关闭按钮
    Cancel = True
      

  2.   

    Private Sub Form_Unload(Cancel As Integer)
        Cancel = True
        Me.WindowState = 1
    End Sub
      

  3.   

    '这是我API浏览器上的一段代码,能实现要求,但不一定是最优
    '原理很简单就是判断鼠标是否在菜单外单击,是,则关闭
    '在Win2000 和XP下测试通过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
      
      intKey = (GetAsyncKeyState(VK_F12) And &HFF00) / 2 ^ 15
      intMouse = (GetAsyncKeyState(VK_LBUTTON) And &HFF00) / 2 ^ 15
     
      
      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
      
    End Sub