Private Declare Sub ClipCursor Lib "user32" (lpRect As RECT)
Private Declare Sub GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT)
Private Declare Sub ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINT)
Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
Private Declare Function ClipCursorBynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)
Private Type POINT
x As Long
y As Long
End Type
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
'锁鼠标
Public Sub LockMouse()
Dim client As RECT
Dim upperleft As POINT
GetClientRect Me.hwnd, client
upperleft.x = client.left
upperleft.y = client.top
ClientToScreen Me.hwnd, upperleft
OffsetRect client, upperleft.x, upperleft.y
ClipCursor client
End Sub
'解鼠标
Public Sub UpMouse()
ClipCursorBynum& 0
End Sub
Private Declare Sub GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT)
Private Declare Sub ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINT)
Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
Private Declare Function ClipCursorBynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)
Private Type POINT
x As Long
y As Long
End Type
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
'锁鼠标
Public Sub LockMouse()
Dim client As RECT
Dim upperleft As POINT
GetClientRect Me.hwnd, client
upperleft.x = client.left
upperleft.y = client.top
ClientToScreen Me.hwnd, upperleft
OffsetRect client, upperleft.x, upperleft.y
ClipCursor client
End Sub
'解鼠标
Public Sub UpMouse()
ClipCursorBynum& 0
End Sub