vb 如何鼠标在窗体外点击任意键结束窗体运行?请写源码。
2个回答
展开全部
Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32 " (ByVal vKey As Long) As Integer
Private Declare Function GetCursorPos Lib "user32 " (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowRect Lib "user32 " (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim p As POINTAPI, r As RECT
Private Sub Timer1_Timer()
Dim a As Long
a = GetAsyncKeyState(1)
If a = -32767 Then
GetCursorPos p
GetWindowRect hwnd, r
If p.X < r.Left Or p.Y < r.Top Or p.X > r.Right Or p.Y > r.Bottom Then Unload Me
End If
End Sub
Private Declare Function GetAsyncKeyState Lib "user32 " (ByVal vKey As Long) As Integer
Private Declare Function GetCursorPos Lib "user32 " (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowRect Lib "user32 " (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim p As POINTAPI, r As RECT
Private Sub Timer1_Timer()
Dim a As Long
a = GetAsyncKeyState(1)
If a = -32767 Then
GetCursorPos p
GetWindowRect hwnd, r
If p.X < r.Left Or p.Y < r.Top Or p.X > r.Right Or p.Y > r.Bottom Then Unload Me
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询