Dejte do Form1 tlačítko Command1 a zkuste:
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Declare Sub ClipCursorRect Lib "user32" Alias "ClipCursor" (lpRect As RECT)
Private Declare Sub ClipCursorClear Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)
Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Command1.Caption = "Zamkni myš"
End Sub
Public Sub ZamkniMys(ByVal lLeft As Long, ByVal lTop As Long, _
ByVal lWidth As Long, ByVal lHeight As Long, _
Optional ByRef oPositionTo As Object = Nothing)
Dim tR As RECT
Dim tP As POINTAPI
' převod twip na pixel
tR.left = lLeft \ Screen.TwipsPerPixelX
tR.top = lTop \ Screen.TwipsPerPixelY
tR.right = (lLeft + lWidth) \ Screen.TwipsPerPixelX
tR.bottom = (lLeft + lHeight) \ Screen.TwipsPerPixelY
'zkontroluje volitelný parametr
If oPositionTo Is Nothing Then Set oPositionTo = Screen
If Not oPositionTo Is Screen Then
tP.X = tR.left
tP.Y = tR.top
ClientToScreen oPositionTo.hWnd, tP
tR.left = tP.X
tR.top = tP.Y
tP.X = tR.right
tP.Y = tR.bottom
ClientToScreen oPositionTo.hWnd, tP
tR.right = tP.X
tR.bottom = tP.Y
End If
ClipCursorRect tR
End Sub
Public Sub OdemkniMys()
ClipCursorClear 0
End Sub
Private Sub Command1_Click()
If Command1.Caption = "Zamkni myš" Then
Command1.Caption = "Odemkni myš"
ZamkniMys 0, 0, Form1.ScaleWidth, Form1.ScaleHeight, Form1
Else
Command1.Caption = "Zamkni myš"
OdemkniMys
End If
End Sub
|