Jump to content
  • Advertisement
Sign in to follow this  

Mouse input

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

What's the best way to get the correct mouse position relative to the DirectX window? Meaning... if my I initialized DirectX to a window size of 800 x 600, how do I get actual coordinates where 0 is the top of the window and 600 is the bottom of the window, regardless of whether the window has been resized or maximized? I started by using Windows messages, which at least gave me something close... however, it was absolute screen coordinates and it wasn't relative to the DirectX window. So I switched over to DirectInput, which returned me relative coordinates. Since I don't have a start position of the mouse, this proved somewhat useless, so I changed to use absolute axis mode, which is giving me freaking huge numbers. Maybe I'm doing something wrong there. What's the best way to do this?

Share this post

Link to post
Share on other sites
Ah, nevermind. Solved it myself. Solution for those who stumble upon this post later.

DirectInput won't work since it has no idea about the actual mouse position on the screen. You have to do it within the Windows messages and convert the number.

info.cbSize = sizeof(WINDOWINFO);
GetWindowInfo( this->GetHWND(), &info);

int x = LOWORD(lParam)*800.0f/float(info.rcClient.right - info.rcClient.left);
int y = HIWORD(lParam)*600.0f/float(info.rcClient.bottom - info.rcClient.top);
if ( message == WM_MOUSEMOVE) {
this->game->MouseMove( x, y );
} else {
this->game->MouseClick( x, y );

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.

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!