I'm using the following code to enable dark mode support. However, the main window already exists at that point (I'm doing that from within a plugin dll), so the menu popups don't switch to the dark theme automatically - some trigger is still missing.
If I switch from fullscreen to a regular window, the menu dropdown suddenly starts using the dark mode. Same when changing the theme in Windows 11 settings (doesn't matter if I switch to a dark or light theme there). The only trick I found so far is SendMessage(hWnd, WM_DWMNCRENDERINGCHANGED, FALSE, 0);
, but that messes up the fullscreen geometry of the main window. Can someone explain what the recommended way to do that is? I guess I could custom draw the popups, but since it starts working after some events, maybe we can identify what these events are and if there is an official solution to the problem.
HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
ASSERT(hUxtheme);
SetPreferredAppMode = (fnSetPreferredAppMode)GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135));
ASSERT(SetPreferredAppMode);
AllowDarkModeForWindow = (fnAllowDarkModeForWindow)GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133));
ASSERT(AllowDarkModeForWindow);
SetPreferredAppMode(PreferredAppMode::ForceDark);
void enableImmersiveDarkMode(HWND hWnd) {
BOOL USE_DARK_MODE = true;
BOOL SET_IMMERSIVE_DARK_MODE_SUCCESS = SUCCEEDED(DwmSetWindowAttribute(
hWnd, DWMWINDOWATTRIBUTE::DWMWA_USE_IMMERSIVE_DARK_MODE,
&USE_DARK_MODE, sizeof(USE_DARK_MODE)));
}