Private Sub Form_Unload(Cancel As Integer) Cancel = True Me.WindowState = 1 End Sub
'这是我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
Cancel = True
Cancel = True
Me.WindowState = 1
End Sub
'原理很简单就是判断鼠标是否在菜单外单击,是,则关闭
'在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