Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

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

Total Hit ( 4508)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
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


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.