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?
Printable View
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?
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.
Thanks, this is just perfect!