Avis Junior Poster

Joined: 07 Oct 2003 Posts: 510 Location: India
|
Posted: Oct 8th, 2003 04:11 AM Post subject: Limit Mouse Cursor Movement to Your Form |
|
|
Add two command buttons (Command1 , Command2) and add the following code :
[vb:1:2b70d9d03b]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 Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) 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[/vb:1:2b70d9d03b] |
|