Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I subscribe to an OS-level event raised when DWM composition/Aero Glass is disabled?

I'm developing a C# application that supports Windows Aero in the main form.

Some applications that do not support Visual Styles, for example GoToMeeting, disable visual styles and my form is wrongly drawn while GoToMeeting is running (the Aero client area is drawn black).

How could I subscribe to a OS event that is fired when visual styles are disabled? Then I could adjust the client area in my window to be correctly drawn.

Managed and unmanaged solutions are valid for me.

Thanks in advance.


EDIT: According to Hans's answer, here is the code to manage this event:

private const int WM_DWMCOMPOSITIONCHANGED = 0x31e;

[DllImport("dwmapi.dll")]
private static extern void DwmIsCompositionEnabled(ref bool pfEnabled);

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_DWMCOMPOSITIONCHANGED)
    {
        bool compositionEnabled = false;
        DwmIsCompositionEnabled(ref compositionEnabled);

        if (compositionEnabled)
        {
           // composition has been enabled
        }
        else
        {
           // composition has been disabled
        }
    }

    base.WndProc (ref m);
}
like image 446
Daniel Peñalba Avatar asked Apr 20 '11 13:04

Daniel Peñalba


1 Answers

Windows sends a message to your toplevel window. You'd trap it in, say, a WndProc override for a Winforms form. Listen for WM_DWMCOMPOSITIONCHANGED, message number 0x31e.

like image 101
Hans Passant Avatar answered Sep 28 '22 19:09

Hans Passant