Mouse input

This topic is 4041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 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.

case WM_MOUSEMOVE:case WM_LBUTTONDOWN:	{		WINDOWINFO info;		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 );		}	}	break;