PDA

View Full Version : [Tutorial]Stop The Cursor From Moving Off Your Form



Dxt-Cobra
09-14-2007, 09:19 AM
Add this code to the Declarations Section:


Dim lTwipsX As Long
Dim lTwipsY As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Dim RectArea As RECT
'
' The ClipCursor function confines the cursor to
' a rectangular area on the screen.
'
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long


Add this to the form_Load event:


Private Sub Form_Load()
lTwipsX = Screen.TwipsPerPixelX
lTwipsY = Screen.TwipsPerPixelY
End Sub

Add a button named cmdTrap with this code:


Private Sub cmdTrap_Click()
Form1.Caption = "Cursor Clipped to the Form"

With RectArea
.Left = Form1.Left / lTwipsX
.Top = Form1.Top / lTwipsY
.Right = .Left + Form1.Width / lTwipsX
.Bottom = .Top + Form1.Height / lTwipsY
End With

Call ClipCursor(RectArea)
End Sub

Add a button named cmdRelease with this code:


Private Sub cmdRelease_Click()
Form1.Caption = "Cursor Released"

With RectArea
.Left = 0
.Top = 0
.Right = Screen.Width / lTwipsX
.Bottom = Screen.Height / lTwipsY
End With
Call ClipCursor(RectArea)
End Sub



this works really well for setting your mouse to the form only
(say your in a game and trying to find the mouse for hitting the buttons)

sshhaaddyy
03-28-2008, 09:41 PM
Wow dude, thanks for this.

Bigxxx
05-14-2008, 01:07 PM
Wow it is great to make a funvirus xD
Just make a button with "restard" fill in code for restart computer and the code for "stop the cursor from moving off your form" ;)
No chance and then allways on top :P