Click to See Complete Forum and Search --> : Help: cursor changes when mouse leaves window?
chrisj
November 21st, 2005, 06:05 PM
I have written code that calls setcapture on the mouse for when it leaves the window area. It successfully gets all the input I want and performs just fine. After I call setcapture, I also switch the cursor around.
The problem:
Once the mouse leaves the window, it reverts back to a standard cursor. Note during this period, my setcapture still works just fine. So the end result is my cursor that I loaded only stays that way inside my window.
How can I make it stay that way at all times until I'm done with it?
(possible answer) Should I call setsystemcursor and muck with all that?
Chris J.
olivthill
November 21st, 2005, 06:58 PM
SetCapture() is often used in conjunction with ClipCursor(), which confines the cursor to a rectangular area on the screen, e.g.
RECT rcClient;
POINT ptClientUL; // client upper left corner
POINT ptClientLR; // client lower right corner
SetCapture(hwnd);
// Retrieve the screen coordinates of the client area,
// and convert them into client coordinates.
GetClientRect(hwnd, &rcClient);
ptClientUL.x = rcClient.left;
ptClientUL.y = rcClient.top;
// Add one to the right and bottom sides, because the
// coordinates retrieved by GetClientRect do not
// include the far left and lowermost pixels.
ptClientLR.x = rcClient.right + 1;
ptClientLR.y = rcClient.bottom + 1;
ClientToScreen(hwnd, &ptClientUL);
ClientToScreen(hwnd, &ptClientLR);
// Copy the client coordinates of the client area
// to the rcClient structure. Confine the mouse cursor
// to the client area by passing the rcClient structure
// to the ClipCursor function.
SetRect(&rcClient, ptClientUL.x, ptClientUL.y, ptClientLR.x, ptClientLR.y);
ClipCursor(&rcClient);
...
...
ClipCursor(NULL);
ReleaseCapture();
chrisj
November 21st, 2005, 08:22 PM
Thanks for the reply. However I'm not trying to keep my cursor inside my window. In fact I want my cursor to go outside my window and perhaps even onto the other screen.
I tried modifying the setsystemcursor, and that worked. However the big problem was that it permentantly set the state of my cursor. Not cool at all! I had to go to my control panel and reset my mouse icons!!!
I tried to get a handle to the old system cursor, but I didn't see any function to do that in the SDK.
Chris J.
Marc G
November 22nd, 2005, 07:31 AM
SetCursor returns the current cursor.
golanshahar
November 22nd, 2005, 09:38 AM
I tried to get a handle to the old system cursor, but I didn't see any function to do that in the SDK.
you can try this code to restore system cursors:
::SystemParametersInfo(SPI_SETCURSORS,0,0,WM_SETTINGCHANGE |SPIF_UPDATEINIFILE );
Cheers
chrisj
November 22nd, 2005, 12:44 PM
SetCursor returns the current cursor.
Good point, I'm using that to get a handle to the old default client area cursor.
chrisj
November 22nd, 2005, 01:07 PM
you can try this code to restore system cursors:
::SystemParametersInfo(SPI_SETCURSORS,0,0,WM_SETTINGCHANGE |SPIF_UPDATEINIFILE );
Cheers
Thanks so much!! That did it. That worked like a charm.
It also introduced me to a whole new section of the MSDN library I hadn't ever seen yet.
golanshahar
November 22nd, 2005, 01:27 PM
Thanks so much!! That did it. That worked like a charm.
your welcome, Glad i could help :wave:
Cheers
miteshpandey
November 22nd, 2005, 02:00 PM
Originally posted by ChrisJ Once the mouse leaves the window, it reverts back to a standard cursor. Note during this period, my setcapture still works just fine.
Note one thing that if any other application calls SetCapture() for its window(s), you will no longer be able to get mouse inputs.
AFAIK, if you continously want the mouse inputs irrespective of the fact that other applications may capture the mouse you have to use mouse hooks.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.