Programming » Visual Basic 6 » Visual Basic 6 Code » Mouse » ");?>
Restricts the moust cursor to a form or control (i.e. it cannot move out).
Private Declare Function ClipCursor Lib "user32" (ByVal lpRect As LongAs 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

Public Sub ClipCursorToForm(F As Form)
    Dim R As RECT
    GetWindowRect F.hwnd, R
    ClipCursor VarPtr(R)
End Sub

Public Sub ClipCursorToControl(C As Control)
    Dim R As RECT
    GetWindowRect C.hwnd, R
    ClipCursor VarPtr(R)
End Sub

Public Sub UnClipCursor()
    ClipCursor 0
End Sub