Jump to content
  • Advertisement
Sign in to follow this  
andrew1b

Still not accurate with ScreenToClient

This topic is 3647 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'm trying to get the screen space cursor position with the functions GetCursorPos and ScreenToClient but it's still not accurate (about 10 pixels missing). POINT point; GetCursorPos(&point); ScreenToClient(hWnd, &point); It works fine on fullscreen mode, but while I'm on windowed mode it don't seem to be perfectly accurate. Why is it happening? Any idea? EDIT: I'm using Direct3D 9

Share this post


Link to post
Share on other sites
Advertisement
But it's not the title bar because I have debuged it and as I put the cursor over the first pixel of the rendering surface it says it's the point 0,0 in client space.

Share this post


Link to post
Share on other sites
If you have a title bar at all, then I'm afraid it probably is the title bar that is making the difference.
I believe you can use AdjustWindowRectEx iirc, to find out the window title bar height. If adjusting by that height works then that proves it.

Share this post


Link to post
Share on other sites
If you're using this for picking, make sure your backbuffer and client area are the same size. If you pass 800x600 to CreateWindow() and CreateDevice(), you'll get a client area that's something like 794x576 and a backbuffer that's 800x600, which means the backbuffer is shrunk onto the client area. The point at (0, 0) is probably correct because the scaling is less evident.

To get around that, you want to use AdjustWindowRectEx, as iMalc said.

Share this post


Link to post
Share on other sites
Thank you! I did it this way and it worked fine:


RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = m_ScreenDim.x;
rect.bottom = m_ScreenDim.y;
const DWORD dwstyle = (WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);

AdjustWindowRectEx(&rect, dwstyle, FALSE, 0);

m_hWnd=CreateWindow(szClassName, m_szWinTitle,
dwstyle, 0, 0, rect.right-rect.left, rect.bottom-rect.top,
GetDesktopWindow(), NULL, wc.hInstance, NULL);

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!