// psuedo code
HWND hwnd = CreateWindow(.., width, height, ...);
RECT almost;
GetClientRect(hwnd, &almost);
SetWindowPos(hwnd, 0, 0, 0,
2*width-almost.right, 2*height-almost.bottom,
SWP_NOMOVE);
The trick basically assumes that the non-client area is bigger than the client area by a constant amount, so you can know how much to overshoot to get the right client size.
I know this has to be a common problem, so is there a better way to do this? I tried to find a deterministic way to translate a desired client rectangle into the size of its surrounding non-client window, but I could find none on MSDN or elsewhere. Any ideas? Thanks
Getting correct client window size
This question involves Win32, so it isn't exactly DirectX, but the line between the two is pretty blurred, so this seemed the appropriate forum.
If I call CreateWindow passing it a width and height, the resulting window's non-client rectangle has this width and height, not the client window. To get the appropriately sized client size rectangle, I have to do a pretty hackish, though thus far reliable, trick:
The function to use to achieve this is AdjustWindowRect.
Then call MoveWindow or UpdateWindow to update your window size.
RECT r = {0, 0, ClientWidth, ClientHeight};AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_style), GetMenu(hWnd));int WindowWidth = r.right - r.left;int WindowHeight = r.bottom - r.top;
Then call MoveWindow or UpdateWindow to update your window size.
You can also call AdjustWindowRect before creating your window, just insert the styles and a TRUE if you've got a menu.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement