Jump to content
  • Advertisement
Sign in to follow this  

Getting correct client window size

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

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:
// 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

Share this post


Link to post
Share on other sites
Advertisement
The function to use to achieve this is AdjustWindowRect.


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.

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!