Advertisement

MouseCoords (75%OffTopic)

Started by December 03, 2001 05:29 PM
7 comments, last by alex211169 23 years, 2 months ago
Hi Forum... How can i receive mousemove-messages while the cursor is outside the windowarea ? what i do right now is this: -create a 50 ms timer that fires WM_TIMER messages -read the cursor-screencoords from those messages -calculate the windowrelative possition (in/out) -set a CursorIsOutsideTheWindow-Flag if out is there a simpler way to be notified when the cursor leaves the windowarea and receive the actual coords ? grz alex
That''s easy

Just call
SetCapture(hWnd);
hWnd being the handle of the window that is to receive the WM_MOUSEMOVE messages...
You have to release it at a later time with
ReleaseCapture();
else there''ll be no way to use the mouse to click on an other window...

Fox Mc Cloud
Advertisement
nope...
SetCapture() wont work..
capture is already set to the window ..
moving the cursor outside the window area causes no WM_CAPTURECHANDED message ..







You can use a hook to do it, but it may be a bit overkillish. Look at the function ''SetWindowsHookEx'' with WH_MOUSE.

[Resist Windows XP''s Invasive Production Activation Technology!]
Or you can use a timer-based approach. The function GetCursorPos will always return the current mouse position. Throw that in a timer and there you go.
You must have done something wrong.
Receiving WM_MOUSEMOVE messages while the mouse is not over your window is why SetCapture exists, and it DOES work perfectly.
WM_CAPTURECHANDED is only sent if your program had the mouse captured and some other program stealed it from you using SetCapture too.
Just use SetCapture(hWnd) and receive your messages with WM_MOUSEMOVE as usual. Also make sure your window is active, an inactive window that captures the mouse only receives the messages when the mouse is over their visible area.

Fox Mc Cloud
Advertisement
this helps...
thank you all !


anonymus "SetCapture" poster:

i found this lines in the msdn-SetCapture-Docs:

If the mouse cursor is over a window created by another thread, the system will direct mouse input to the specified window *ONLY* if a mouse button is down.

so do i have to press a mousebutton all the time ?





I was the Anonymous Poster up there. I thought my name on the bottom would have been enough to see who was the poster... anyway I''m registered now.

About your question, that''s pretty much the opposite. It simply means that capturing the mouse allows you to see where the mouse moves on the screen while your app is active, but if the user clicks on another window it will become active, and your app will be back to normal.
I guess if he then clicks on your app again you''ll receive the WM_MOUSEMOVE for the whole screen again, but you''d have to check.

That said, only capturing the mouse when the user clicks a button and releasing it when he releases it is a good practice in my way.
--New feature - Windows users, press ALT-F4 to launch the IQ test.
Hello there,

you could use a combination of

GetCursorPos to get the position of the mouse and
GetAsyncKeyState to get the button states of the mouse.

either on a timer or in your main render loop.

Mark.

This topic is closed to new replies.

Advertisement