Question

I want to compute the minimum size both vertical and horizontal that will contain a dialog. I used GetClientRect to determine the width and height. Then for the width when a vertical scroll bar is needed I added GetSystemMetrics (SM_CXVSCROLL) + GetSystemMetrics (SM_CXSIZEFRAME) but I seem to come up a few pixels short.

What GetSysMetrics do I need to take into account for both the horizontal and vertical dimensions with and without scroll bars?

Was it helpful?

Solution

You need to account for window borders and other non-client area space. The easiest way to do this is use AdjustWindowRect() or AdjustWindowRectEx(). However, you will still need to handle the scroll bars yourself:

From the documentation:

The AdjustWindowRectEx function does not take the WS_VSCROLL or WS_HSCROLL styles into account. To account for the scroll bars, call the GetSystemMetrics function with SM_CXVSCROLL or SM_CYHSCROLL.

So, the steps are:

  1. GetClientRect() to get your minimum size client area.

  2. AdjustWindowRectEx() to convert the client size to window size based on your window styles.

  3. If needed, apply additional adjustments to account for scroll bars (GetSystemMetrics() with SM_CXVSCROLL and/or SM_CYHSCROLL).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top