devxlogo

ClipMouseToWindow – Confine the cursor to a window’s client area

ClipMouseToWindow – Confine the cursor to a window’s client area

Private Type RECT    Left As Long    Top As Long    Right As Long    Bottom As LongEnd TypePrivate Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, _    lpRect As RECT) As LongPrivate Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, _    lpPoint As Any) As LongPrivate Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long' confine (clip) the mouse's cursor to the client' area of a given window or control.' if the argument is omitted, any current clipping is canceledSub ClipMouseToWindow(Optional ByVal hWnd As Long)    Dim rcTarg As RECT        If hWnd Then        ' clip the mouse to the specified window        ' get the window's client area        GetClientRect hWnd, rcTarg        ' convert to screen coordinates. Two steps:        ' first, the upper-left corner        ClientToScreen hWnd, rcTarg        ' next, the bottom-right corner        ClientToScreen hWnd, rcTarg.Right        ' finally, we can clip the cursor        ClipCursor rcTarg    Else        ' unclip the mouse if no argument has been passed        ClipCursor ByVal 0&    End IfEnd Sub

See also  Get the Most Out of Virtual Credit Cards For Business
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist