dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Jun 24, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


ClipMouseToWindow - Confine the cursor to a window's client area

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, _
    lpRect As RECT) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, _
    lpPoint As Any) As Long
Private 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 canceled

Sub 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 If
End Sub
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date