HeaderPane
Main

Dark Mode Support

Share Link
Print

SftDarkMode_GetNaturalChildSize

Compute the natural content size of a form-style window by unioning the bounding rects of its direct children. Useful for computing scroll ranges in CScrollView or any host that needs to size itself to its template content.

C

SIZE SftDarkMode_GetNaturalChildSize(HWND hwnd, int padRight, int padBottom);

Parameters

hwnd

The parent window whose direct children should be measured.

padRight

Right-edge padding to add to the union, in pixels. Pass 0 for no padding. The padding ensures the rightmost control is not flush against the parent's edge.

padBottom

Bottom-edge padding to add to the union, in pixels. Pass 0 for no padding.

Return Value

A SIZE whose cx / cy are the width and height of the union of every direct child's bounding rect, in hwnd's client coordinates, plus the padding. Returns {0, 0} if hwnd is NULL or has no children.

Comments

Despite living in the SftDarkMode header, this is a general-purpose layout helper - it is unrelated to dark mode and has no dependency on the rest of the helper. It is included here because the same dialog hosts that need the dark-mode helpers (CFormView, dialog templates rendered as scrolling forms) typically also need a natural-size computation after a PerMonitorV2 DPI change.

Under PerMonitorV2 DPI awareness, Windows repositions the dialog-template children automatically when the host moves to a different-DPI monitor. After the repositioning, the union of the children's bounding rects is the new natural size at the new DPI, with no manual MulDiv required. Pass the result to CScrollView::SetScrollSizes (or equivalent) to update the scrollbar range.

// In OnSize / OnDpiChangedAfterParent:
SIZE szContent = SftDarkMode_GetNaturalChildSize(m_hWnd, 16, 16);
SetScrollSizes(MM_TEXT, szContent);

The function does not recurse - only direct children are considered. Composite controls that own internal children contribute their outer bounding rect, not their inner layout.

See Also ApplyToDialog


Last Updated 05/09/2026 - (email)
© 2026 Softel vdm, Inc.