How to receive WM_SETTINGCHANGE message in WinUI3 when system theme changes

Shyam Butani 135 Reputation points
2024-05-22T06:54:06.97+00:00

Hi,

I want to capture system theme change event in my WinUI3 app. I'm trying like below code snippet, but not receiving WM_SETTINGCHANGE message there.

void 
TWWinUI3App::OnLaunched(LaunchActivatedEventArgs const&) {
	// ...
	
	Window window = Window();
    window.Title(L"TW Window");
    HWND hwnd;
    int rc;
    
	rc = window.try_as<IWindowNative>()->get_WindowHandle(&hwnd);
    rc = SetWindowSubclass(hwnd, SUBCLASSPROC(TWWinUI3App::WindowSubClassHandler), 0, 0);

	// ...
}

LRESULT CALLBACK 
TWWinUI3App::WindowSubClassHandler (HWND pHwnd, UINT pMessageCode, WPARAM pWParam, LPARAM pLParam, [[maybe_unused]] UINT_PTR pIdSubclass, [[maybe_unused]] DWORD_PTR pRefData)
{
    switch (pMessageCode) {

    case WM_SETTINGCHANGE: {

      
		// SETTINGS_CHANGED
        break;
    }

    default:
        return DefSubclassProc(pHwnd, pMessageCode, pWParam, pLParam);
    }
}

Correct me if I'm missing anything.

Thanks.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
737 questions
{count} votes

0 additional answers

Sort by: Most helpful