Try this
Code:
Option Explicit
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 Any) As Long
Private Declare Function GetWindowRect Lib "user32.dll" _
(ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long
Private Sub cmdClip_Click()
' Confines the cursor temporarily to inside of a picture control
Dim r As RECT ' confinement rectangle
Dim retval As Long ' return value
retval = GetWindowRect(Picture1.hwnd, r) ' put window's coordinates into r
retval = ClipCursor(r) ' confine the cursor to the boundries defined in r
End Sub
Private Sub cmdUnclip_Click()
' Unconfine the cursor (actually...confine it to the size of the desktop)
Dim r As RECT, retval As Long
Dim deskhWnd As Long ' the handle of the desktop window
deskhWnd = GetDesktopWindow() ' get handle of the desktop window
retval = GetWindowRect(deskhWnd, r) ' put window's coordinates into r
retval = ClipCursor(r) ' "confine" the cursor to the entire screen
End Sub
Bookmarks