Still not accurate with ScreenToClient
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
10 pixels sounds suspiciously like the titlebar. The client area starts below the titlebar.
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.
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.
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.
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.
To get around that, you want to use AdjustWindowRectEx, as iMalc said.
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);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement