Article ID: 179192
Article Last Modified on 7/1/2004
Option Explicit
Private Type RECT
left As Integer
top As Integer
right As Integer
bottom As Integer
End Type
Private Type POINT
x As Long
y As Long
End Type
Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
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 Sub Form_Load()
Command1.Caption = "Limit Cursor Movement"
Command2.Caption = "Release Limit"
End Sub
Private Sub Command1_Click()
'Limits the Cursor movement to within the form.
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
Private Sub Command2_Click()
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
Additional query words: kbVBp500 kbVBp600 kbVBp kbdsd kbDSupport KBWIN32SDK KBAPI
Keywords: kbhowto KB179192