VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Limits the Cursor movement to within the form

by Khaldoun Baz (12 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 8th October 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Limits the Cursor movement to within the form

Rate Limits the Cursor movement to within the form



    left As Long
    top As Long
    right As Long
    bottom As Long
End Type
Private Type POINT
    x As Long
    y As Long
End Type
Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT)
Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT)
Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
Private Sub Form_Load()
    'KPD-Team 1999
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    Command1.Caption = "Limit Cursor Movement"
    Command2.Caption = "Release Limit"
End Sub
Private Sub Command1_Click()
    'Limits the Cursor movement to within the form.
    Dim client As RECT
    Dim upperleft As POINT
    'Get information about our wndow
    GetClientRect Me.hWnd, client
    upperleft.x = client.left
    upperleft.y = client.top
    'Convert window coördinates to screen coördinates
    ClientToScreen Me.hWnd, upperleft
    'move our rectangle
    OffsetRect client, upperleft.x, upperleft.y
    'limit the cursor movement
    ClipCursor client
End Sub
Private Sub Command2_Click()
    'Releases the cursor limits
    ClipCursor ByVal 0&
End Sub
Private Sub Form_Unload(Cancel As Integer)
    'Releases the cursor limits
    ClipCursor ByVal 0&
End Sub


Download this snippet    Add to My Saved Code

Limits the Cursor movement to within the form Comments

No comments have been posted about Limits the Cursor movement to within the form. Why not be the first to post a comment about Limits the Cursor movement to within the form.

Post your comment

Subject:
Message:
0/1000 characters