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?
You need to account for window borders and other non-client area space. The easiest way to do this is use
AdjustWindowRect()
orAdjustWindowRectEx()
. However, you will still need to handle the scroll bars yourself:From the documentation:
So, the steps are:
GetClientRect()
to get your minimum size client area.AdjustWindowRectEx()
to convert the client size to window size based on your window styles.If needed, apply additional adjustments to account for scroll bars (
GetSystemMetrics()
withSM_CXVSCROLL
and/orSM_CYHSCROLL
).