开发者

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

开发者 https://www.devze.com 2023-02-27 02:20 出处:网络
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 wrongl

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);
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消