Please read this entire post before suggesting AdjustWindowRect[Ex], as it does not work (it gives bogus values, only accounting for one row of menu items) for what I need.
I've been fighting with this for over 5 hours now, and I just can't figure out how to set my client areas properly when a menu needs to have two or more "rows".
Basically, my problem is, I want to have the client area of my application be properly calculated, regardless of the menu height (sometimes my menu creates a second row for whatever reason, it'd be nice if I could keep them all on one row with a scroll arrow or something. I've tried multiple methods with no success.
Here's one example I tried (pulled from Google):
If I pass 160, 144, for example, the client area/size is correct, but if I make it something like 320, 288 (e.g. 160 and 144 doubled), it's wrong, set to 320, 307 on the first call, then the correct 320, 288 on the next call (presumably because on the first call, the menu is 2 rows, then it's 1 row on the next call).
Also tried this:
Is there some way to calculate what the menu height will be before actually adjusting the size of the window? :\
Or, if that's not possible, can the menu somehow be forced to stay on one row?
Edit: I noticed Qt keeps its menu bars on one row, but I'm assuming they use custom code for that.. *sigh*
I've been fighting with this for over 5 hours now, and I just can't figure out how to set my client areas properly when a menu needs to have two or more "rows".
Basically, my problem is, I want to have the client area of my application be properly calculated, regardless of the menu height (sometimes my menu creates a second row for whatever reason, it'd be nice if I could keep them all on one row with a scroll arrow or something. I've tried multiple methods with no success.
Here's one example I tried (pulled from Google):
Code:
SetWindowSize(int width, int height)
{
RECT rcClient, rcWindow;
POINT ptDiff;
GetClientRect(hWnd, &rcClient);
GetWindowRect(hWnd, &rcWindow);
ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
MoveWindow(hWnd, rcWindow.left, rcWindow.top, width + ptDiff.x, height + ptDiff.y, TRUE);
GetClientRect(hWnd, &rcClient);
}
Also tried this:
Code:
void SetWindowSize(int width, int height)
{
RECT client, window;
GetClientRect(hWnd, &client);
GetWindowRect(hWnd, &window);
long desWidth = 0;
long desHeight = 0;
const long windowWidth = window.right - window.left;
const long windowHeight = window.bottom - window.top;
const long clientWidth = client.right - client.left;
const long clientHeight = client.bottom - client.top;
const long totalBorderWidth = windowWidth - clientWidth;
long menuHeight2 = windowHeight - clientHeight;
desWidth = totalBorderWidth + width;
desHeight = (windowHeight - clientHeight) + height;
SetWindowPos(hWnd, nullptr, window.left, window.top, desWidth, desHeight, SWP_NOMOVE);
}
Or, if that's not possible, can the menu somehow be forced to stay on one row?
Edit: I noticed Qt keeps its menu bars on one row, but I'm assuming they use custom code for that.. *sigh*