So for a game project I am creating a game window (of course), but I only know the client size of the window and not the actual size. I know how to calculate the size but I am getting incorrect results when I am testing to see the size of the client area (should be the same as the input).
void NewWindow(width, height)
{
// Code setting things up here.
if (!fullscreen) // Convert client size to window size.
{
style = WS_OVERLAPPEDWINDOW;
RECT r = RECT();
r.top = 0;
r.bottom = height;
r.left = 0;
r.right = width;
AdjustWindowRect(&r, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, FALSE);
w = r.right;
h = r.bottom;
}
hWnd = CreateWindow(CLASS_NAME, title, style, CW_USEDEFAULT, CW_USEDEFAULT, w, h, NULL, NULL, GetModuleHandle(NULL), (LPVOID)NULL);
}
And the code for getting the client size is:
Size Game::GetClientSize()
{
RECT r = RECT();
GetClientRect(hWnd, &r);
return Size(r.right - r.left, r.bottom - r.top);
}
I am not sure where the problem is, because AdjustWindowRect seems to be outputting a value larger than what I put in...
Thanks, Philip
The style you pass to AdjustWindowRect should be the same style you pass to CreateWindow. Otherwise they will mismatch. You also need to calculate width as right - left, and height as bottom - top, since the adjusted rect usually has a negative origin relative to the origin of the client area.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With