To test it, just open a Visual Basic project with a form in it. Copy the sourcecodes and paste to the declaration section of the form. Then put two command buttons in the form.
You can limit the cursor movement within any control in Visual Basic. Just change the 'Me.hwnd' with the control's hwnd property. Ex: Command1.hWnd
'-->API Declaration
Private Declare Sub ClientToScreen Lib "user32" _
(ByVal hwnd As Long, lpPoint As POINT)
Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
Private Declare Sub OffsetRect Lib "user32" _
(lpRect As RECT, ByVal X As Long, ByVal Y As Long)
Private Declare Sub GetClientRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT)
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 Sub Command1_Click()
Dim Client As RECT
Dim Up As POINT
ClientToScreen Me.hwnd, Up
GetClientRect Me.hwnd, Client
OffsetRect Client, Up.X, Up.Y
Up.X = Client.Left
Up.Y = Client.Top
ClipCursor Client
End Sub
Private Sub Command2_Click()
ClipCursor ByVal 0&
End Sub
Private Sub Form_Load()
Command1.Caption = "&Limit Cursor"
Command2.Caption = "&Remove Cursor Limit"
End Sub
0 comments:
Post a Comment