7

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);
}
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
  • 1
    Would detecting if Aero is enabled what you're after? If so, this may help: http://stackoverflow.com/questions/5114389/how-make-sure-areo-effect-is-enabled – joshhendo Apr 20 '11 at 13:04

1 Answers1

5

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536