Click to See Complete Forum and Search --> : How to change the area for moving the mouse


Alex999H
February 17th, 2000, 08:35 AM
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

Cakkie
February 17th, 2000, 08:55 AM
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
slisse@planetinternet.be

The best way to escape a problem, is to solve it.