Jump to content
  • Advertisement

Archived

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

lost hope

Mouse Pos - Not Full Screen

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

Hello, For an app that I''m writing (in Windows), I need to get the mouse coord from time to time. I can do this using GetCursorPos, but then it''s always relative to the entire screen (I want to be able to give the user the option of running in fullscreen or windowed mode). This creates a bit of a problem, as I''m drawing things relative to the program''s window, and then getting the mouse coordinates relative to the whole monitor. Does anybody know a way around this? There must be a way to make this simple adjustment. Thanks =)

Share this post


Link to post
Share on other sites
Advertisement
Well shoot, I should have looked around a bit more before posting, as I just figured it out =) In case anybody cares:

// g_hWnd is a global variable for my window handle
// g_height is a global variable storing the current window height

POINT mouse_position;
GetCursorPos (&mouse_position);

if (g_hWnd == WindowFromPoint(mouse_position)){
RECT the_window_rect;
GetWindowRect (g_hWnd, &the_window_rect);

// mouse_x and mouse_y store the mouse coords relative to the window with 0,0 being the bottom left corner

int mouse_x = mouse_position.x - the_window_rect.left;
int mouse_y = g_height + (mouse_position.y - the_window_rect.bottom);

} // end if [associated with mouse over my app''s window]

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.

GameDev.net 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!