Hello All,
I'm looking for code to limit the mouse cursor to only the boundries of a userform until the userform is closed. I have found some vb code for this as an API, but cannot seem to get the code to work.
I'm using Excel 2002, Windows XP, and the error I'm encountering is:
"Compile error, Method or Data member not found" on :GetClientRect Me.hWnd, client.
Here is the code I'm using:
Any help with this is much appreciated.
Thanks in advance.
I'm looking for code to limit the mouse cursor to only the boundries of a userform until the userform is closed. I have found some vb code for this as an API, but cannot seem to get the code to work.
I'm using Excel 2002, Windows XP, and the error I'm encountering is:
"Compile error, Method or Data member not found" on :GetClientRect Me.hWnd, client.
Here is the code I'm using:
Code:
Option Explicit
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
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 CommandButton1_Click()
'Limits the Cursor movement to within the form.
Dim client As RECT
Dim upperleft As POINT
'Get information about our window
GetClientRect Me.hWnd, client
upperleft.x = client.left
upperleft.y = client.top
'Make the bottom and right the same as the top/left
client.bottom = client.top
client.right = client.left
'Convert window coordinates to screen coordinates
ClientToScreen Me.hWnd, upperleft
'offset our rectangle
OffsetRect client, upperleft.x, upperleft.y
'limit the cursor movement
ClipCursor client
End Sub
Private Sub CommandButton2_Click()
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
Private Sub UserForm_Activate()
CommandButton1.Caption = "Limit Cursor Movement"
CommandButton2.Caption = "Release Limit"
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Releases the cursor limits
ClipCursor ByVal 0&
End Sub
Any help with this is much appreciated.
Thanks in advance.