Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Limit Mouse Cursor Movement to Your Form
View previous topic :: View next topic  
Author Message
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Oct 8th, 2003 04:11 AM    Post subject: Limit Mouse Cursor Movement to Your Form Reply with quote

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]
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic