Advertisement Jump to content
Sign in to follow this  

How to get mouse position in c++ window?

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

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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!