Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

BusyBee

Where is the mouse now?

This topic is 5304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I beleive I should use Motion Function ,or something about mouse events but don''t know how exactly ?. who could show me the code of how to locate mouse pointer location in the window and output it as x and y ?. Thanks in advance for any help.

Share this post


Link to post
Share on other sites
Advertisement
Put this in WinProc


case WM_MOUSEMOVE:
{
MouseX = LOWORD(lParam);
MouseY = HIWORD(lParam);
} break;


But you will get the coords starting at zero from the top left of the window, but I don't like that, I like the orgin at the bottom left So..


case WM_MOUSEMOVE:
{
MouseX = LOWORD(lParam);
MouseY = SCREEN_HEIGHT-HIWORD(lParam)-34;
} break;

(did the -34 because it counts the title bar I guess :/, or my SCREEN_HEIGHT is off)

I guess it's a matter of prefrence...

- DarkNebula

[edited by - DarkNebula on April 10, 2004 4:09:12 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by DarkNebula
(did the -34 because it counts the title bar I guess :/, or my SCREEN_HEIGHT is off)
GetSystemMetrics.

@BusyBee:
If you need the mouse cursor position at random times (ie, not necessarily when it moves), there''s also GetCursorPos.

Share this post


Link to post
Share on other sites
The name SCREEN_WIDTH might be a little misleading... for my current project I''m using a window. Does that work with a window? I only quickly glanced at it. I got the impression it was screen related.

- DarkNebula

Share this post


Link to post
Share on other sites
quote:
Original post by DarkNebula
The name SCREEN_WIDTH might be a little misleading... for my current project I''m using a window. Does that work with a window? I only quickly glanced at it. I got the impression it was screen related.
GetClientRect and GetWindowRect.

Share this post


Link to post
Share on other sites
There are also functions that will take care of all the math of converting coordinates for you: ScreenToClient and ClientToScreen. You should use GetCursorPos to retrieve the mouse position when it is not passed to your function (if it is not a message handler, for example).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!