API限制鼠标光标范围
ClipCursor
ClipCursorByNum
Option Explicit
Dim R As RECT
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function ClipCursor Lib “user32″ (lpRect As RECT) As Long
‘lpRect-鼠标光标限制到的矩形
Private Declare Function ClipCursorByNum Lib “user32″ Alias “ClipCursor” (lpRect As Long) As Long
‘lpRect-传0,取消鼠标光标限制
Private Declare Function SetRect Lib “user32″ (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Sub Form_Load() ‘窗体载入后,鼠标只能在窗体范围内移动
SetRect R, Left / Screen.TwipsPerPixelX, Top / Screen.TwipsPerPixelY, (Left + Width) / Screen.TwipsPerPixelX, (Top + Height) / Screen.TwipsPerPixelY
ClipCursor R
End Sub
Private Sub Form_Unload(Cancel As Integer) ‘窗体退出时,取消鼠标光标限制范围
ClipCursorByNum 0
End Sub