TrapMouse (2)



Option Explicit

Private Type Rect
left As Long
top As Long
right As Long
bottom As Long
End Type

Private Declare Function ClipCursor _
Lib "user32" _
(lpRect As Rect) As Long

Private Declare Function ClipCursorBynum _
Lib "user32" _
Alias "ClipCursor" _
(ByVal lpRect As Long) As Long

Private Sub Command1_Click()
Dim dl As Long
Dim myRect As Rect
With myRect
.left = ((Screen.Width - Width) \ 2) \ Screen.TwipsPerPixelX + 5
.top = ((Screen.Height - Height) \ 2) \ Screen.TwipsPerPixelY + 25
.right = ((Screen.Width + Width) \ 2) \ Screen.TwipsPerPixelX - 5
.bottom = ((Screen.Height + Height) \ 2) \ Screen.TwipsPerPixelY - 5
End With
dl = ClipCursor(myRect)
End Sub

Private Sub Command2_Click()
Dim dl As Long
dl = ClipCursorBynum(0)
End Sub

Private Sub Form_Load()
Caption = "Clip Cursor"
Command1.Caption = "Lock"
Command2.Caption = "Unlock"
End Sub


(trapmouse2.html)- by Paolo Puglisi - Modifica del 25/3/2019