Search code examples
c#windowswinformseffectsdwm

How do I achieve desktop overlay blur on Windows?


When I was installing AMD graphics drivers on Windows 10, I noticed a blurred background look, which is a style I want to achieve in my application.

AMD Radeon Installer

I have tried using UpdateLayeredWindow, but it does not apply a blur effect. I have tried using DwmExtendFrameIntoClientArea and DwmEnableBlurBehindWindow but I am unsure how to customize window coloring and image overlays.

There is a DwmGetColorizationColor function, but there is no matching DwmSetColorizationColor function. There are ways to set system-wide coloring, but I would like colorization to affect solely my application window. Also, Aero Glass™ was removed from Windows 8 and 10.

How do I include these effects in my application using WinForms in a way that works on Windows 8/10? If WPF can render these effects, how does it do it and how do I achieve a similar effect on WinForms?


Solution

  • After months of searching, I have finally found the answer. To achieve the glass effect on Windows 10, one must use the undocumented SetWindowCompositionAttribute function in user32.dll.

    Windows 10 Aero Glass Demonstration

    BOOL WINAPI SetWindowCompositionAttribute(HWND hwnd, WINCOMPATTRDATA* pAttrData)
    

    where the layout of the WINCOMPATTRDATA structure is:

    struct WINCOMPATTRDATA {
        DWORD attribute; // the attribute to query, see below
        PVOID pData; //buffer to store the result
        ULONG dataSize; //size of the pData buffer
    };
    

    and attribute can have values from the DWMWINDOWATTRIBUTE enum.