CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Setting cursur area

    Is it possible to limit the area where the cursor may go. Like I want the cursor only be able to be over a bar of buttons I created.

    Any suggestions?


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

    Re: Setting cursur area

    Use the API ClipCursor, but this brings a little hazard with it, MAKE SURE TO READ THE WARNING AT THE BOTTON OF THIS POST!


    'insert this in module
    Declare function ClipCursor Lib "user32.dll" (lpRect as RECT) as long
    Declare function GetWindowsRect Lib "user32.dll" (byval hwnd as long, lpRect as RECT) as long
    Declare function GetDesktopWindow Lib "user32.dll" () as long
    Type RECT
    left as long
    top as long
    right as long
    bottom as long
    end type

    'insert this anywhere you want (this case a form)

    private sub Command1_Click()
    'set the clip to the current window
    dim myRect as RECT
    dim retVal as long

    'use the windows coordinates as RECT and return them to myRect
    retVal = GetWindowRect(Form1.hWnd, myRect)
    'clip the cursor in the forms coordinates
    retVal = ClipCursor(myRect)

    End Sub

    private sub Command2_Click()
    'set the clip to the desktop
    'be sure to use this whenever your program exits
    dim winRect as RECT
    dim desktopHWnd as long
    dim retVal as long

    desktopHWnd = GetDesktopWindow()
    'use the desktops coordinates as RECT and return them to winRect
    retVal = GetWindowRect(Form1.hWnd, winRect)
    'clip the cursor to the desktop
    retVal = ClipCursor(winRect)

    End Sub





    WARNING: be sure to always set the clip back to the size of the desktop
    If you don't, the cursor will remain in there, even when the program exits
    This could lead to serious unwanted concequenses!

    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)

  3. #3
    Guest

    Re: Setting cursur area

    Thanks, this is just perfect!


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