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)
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)