Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

How to get mouse position in c++ window?

This topic is 4733 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

Hi, ive got a window(dimensions x50,y30,width100,height200) in c++, and I want to get the window's mouse position on my window. What would I do? THanks

Share this post


Link to post
Share on other sites
Advertisement
johnny,

In a Windows operating environment you can generally make the following calls:

// Call this function to get the position of the mouse in screen coordinates
BOOL GetCursorPos( LPPOINT lpPoint );

// Call this function to convert to client coords
// here hWnd refers to the window you're trying to make the coordinates
// relative to
BOOL ScreenToClient( HWND hWnd, LPPOINT lpPoint );

Share this post


Link to post
Share on other sites
POINT mousePos;
GetCursorPos(&mousePos); // Get the mouse cursor 2D x,y position

// Mouse x Position = mousePos.x
// Mouse y Position = mousePos.y

if( (mousePos.x == 10) && (mousePos.y == 10) ) return 1;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!