HeaderPane
Main

Dark Mode Support

Share Link
Print

SftDarkMode_ApplyToDialog

Apply dark mode to a dialog and all of its children in one call. The recommended one-shot helper to invoke from WM_INITDIALOG (plain Win32) or OnInitDialog (MFC).

C

void SftDarkMode_ApplyToDialog(HWND hwndDlg);

Parameters

hwndDlg

The dialog window handle.

Comments

ApplyToDialog performs four steps:

  1. Sets (or clears) the SftDarkModeScrollBar window property on the dialog. The IAT hook installed by SftDarkMode_Init checks this property to decide whether to redirect a scrollbar theme lookup to Explorer::ScrollBar (dark) or leave it at the default (light). Setting the property on the dialog opts every direct child in.
  2. Calls SftDarkMode_ApplyToWindow on the dialog so the title bar and frame switch to the dark color.
  3. Applies the DarkMode_Explorer theme class to the dialog itself (or strips the theme in light mode), then sends WM_THEMECHANGED so comctl32 reopens its scrollbar theme handle. This is needed for dialog hosts (CFormView, etc.) that own NC scrollbars - without it, the cached scrollbar theme handle persists until the window is destroyed.
  4. Calls SftDarkMode_ApplyToChildren to theme every direct child, then redraws the entire NC tree with RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN so scrollbar bitmaps repaint at the new theme colors.

Call ApplyToDialog from WM_INITDIALOG once. Re-call it after toggling the dark state through SftDarkMode_SetActive so the dialog and children re-theme to match. The WM_SETTINGCHANGE branch of SftDarkMode_HandleDialogMessage re-applies dark mode automatically when the user flips the Windows setting - applications that route every dialog through HandleDialogMessage do not need to handle WM_SETTINGCHANGE themselves.

ApplyToDialog is also the right call for an MFC CFormView or other non-modal form host: theming requires the same dialog property + theme + child sweep regardless of whether the parent is a DIALOGEX template or a CFormView with a dialog template.

See Also ApplyToWindow | ApplyToChildren | HandleDialogMessage | Init


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