Jump to content
  • Advertisement
Sign in to follow this  
fatima

Mouse Position

This topic is 3172 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 I want to write a class for UI using directx and C++. my problem is detecting mouse over state. I can get mouse position using Win32 function GetCursorPosition(...) or by extracting x,y from WM_MouseMove and etc...but they work only in fullscreen mode and even in fullscreen mode if user change the screen resolution , result will be wrong. absolutely they are not wrong,but I don't know how to calculate the correct state.
if(mouseposition.x> ourcontrol.x && mouseposition.x < ourcontrol.x + ourcontrol.width)
{
// do same for y
{
return true;
}
return false;
}

sorry for my english.

Share this post


Link to post
Share on other sites
Advertisement
GetCursorPos() and the values from WM_MOUSEMOVE are in client area coordinates. You want to make sure that the client area is the same size as the backbuffer.

When you create a window, you need to call AdjustWindowRectEx to get the size of the window based on the size of the client area. In fullscreen, with WS_POPUP, the client area size equals the window rectangle size, so it'll "just work" then.

How do you change resolution in your game? In fullscreen, the mouse window rect should be the same size as the client rect, so mouse coordinates should be pixels.

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.

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!