CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2000
    Posts
    6

    How to change the area for moving the mouse

    Hey,

    I'd like to change the Area for moving the mouse.
    For Example: The Mouse may be moved from Pixels 100(xpos) and 100(ypos) until Pixels 400(xpos) and 400(ypos).

    How can I do that?

    Alexander Holtkamp


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: How to change the area for moving the mouse

    Use the API ClipCursor

    This code clips the cursor to the current window.
    WARNING: you must release the cursor (set the clip to the entire screen) before you end your app, otherwise the cursor will remain clipped, even if your app ends and that is something you don't want(trust me, i've been there)


    Declare Function ClipCursor Lib "user32.dll" (lpRect as RECT) as Long
    Declare Function GetDesktopWindow Lib "user32.dll" () as Long
    Declare Function GetWindowRect Lib "user32.dll" (byval hwnd as Long, lpRect as RECT) as Long

    Type Rect
    left as Long
    top as Long
    right as Long
    bottom as Long
    End Type


    private sub Command1_Click
    Dim r as RECT
    retval = GetWindowRect(Form1.hWnd, r) ' put window's coordinates into r
    retval = ClipCursor(r) ' mouse will be clipped inside the window
    End sub

    private sub Command2_Click

    Dim r as RECT, retval as Long
    Dim deskhWnd as Long ' the handle of the desktop window
    deskhWnd = GetDesktopWindow() ' get handle of the desktop window
    retval = GetWindowRect(deskhWnd, r) ' put window's coordinates into r
    retval = ClipCursor(r) ' clip the cursor to the entire screen

    end sub





    Tom Cannaerts
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured