Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6039965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:26:47+00:00 2026-05-23T06:26:47+00:00

I need, for my WPF app, to detect when the DWM is turned on/off

  • 0

I need, for my WPF app, to detect when the DWM is turned on/off or when the system theme changes.
There is such an event in WinForms, but I can’t see any in WPF.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:26:48+00:00Added an answer on May 23, 2026 at 6:26 am

    I haven’t heard of a WinForms event that fires when a WinForms window receives messages from the system, however it has its own WndProc() method that you can override. You’re probably confusing window messages for form events. Ah, so it’s the StyleChanged event that gets invoked in WinForms windows. The rest of my answer still stands though.

    WPF isn’t closely tied to the Windows API either as it’s a high-level technology that invests a lot of abstraction away from the internals. For one, it draws everything in a window by itself, and doesn’t ask the system to do the drawing for it (EDIT: which is why WPF lacks such a StyleChanged event). That said, Windows sends messages to all windows when the DWM is toggled and when the theme changes, and you can still drill down into the low level from the WPF layer to access these messages and manipulate your WPF controls accordingly.

    Attach a window procedure to your WPF window’s HWND (window handle) as part of your window’s SourceInitialized event. In your window procedure, handle the WM_DWMCOMPOSITIONCHANGED and WM_THEMECHANGED window messages respectively.

    Here’s a quick example (with boilerplate code adapted from this question of mine):

    private IntPtr hwnd;
    private HwndSource hsource;
    
    private const int WM_DWMCOMPOSITIONCHANGED= 0x31E;
    private const int WM_THEMECHANGED = 0x31A;
    
    private void Window_SourceInitialized(object sender, EventArgs e)
    {
        if ((hwnd = new WindowInteropHelper(this).Handle) == IntPtr.Zero)
        {
            throw new InvalidOperationException("Could not get window handle.");
        }
    
        hsource = HwndSource.FromHwnd(hwnd);
        hsource.AddHook(WndProc);
    }
    
    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        switch (msg)
        {
            case WM_DWMCOMPOSITIONCHANGED: 
            case WM_THEMECHANGED:         
    
                // Respond to DWM being enabled/disabled or system theme being changed
    
                return IntPtr.Zero;
    
            default:
                return IntPtr.Zero;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF app in which I need to programatically manipulate at runtime.
I need to tie a WPF-Command to the MouseEnter event of a Stackpanel. How
I need to write an WPF(4.0) application which has a DB but no tables
I need my WPF app to use a true-type font for a different language.
In a WPF app, what XAML code do I need to do the same
When writing a MVVM WPF app, there's always a point where the view model
I am developing a WPF app using MVVM and need some help. for the
I need to implement some kind of RBAC for a WPF app that I'm
So we built a WPF app, now for our next version we need a
I need in wpf app check messages on server. I have own method which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.