Skip to content

Instantly share code, notes, and snippets.

@ysc3839
Last active February 3, 2023 06:20
Embed
What would you like to do?
HMODULE hUser = GetModuleHandleA("user32.dll");
if (hUser)
{
pfnSetWindowCompositionAttribute setWindowCompositionAttribute = (pfnSetWindowCompositionAttribute)GetProcAddress(hUser, "SetWindowCompositionAttribute");
if (setWindowCompositionAttribute)
{
ACCENT_POLICY accent = { ACCENT_ENABLE_BLURBEHIND, 0, 0, 0 };
WINDOWCOMPOSITIONATTRIBDATA data;
data.Attrib = WCA_ACCENT_POLICY;
data.pvData = &accent;
data.cbData = sizeof(accent);
setWindowCompositionAttribute(hWnd, &data);
}
}
#pragma once
typedef enum _WINDOWCOMPOSITIONATTRIB
{
WCA_UNDEFINED = 0,
WCA_NCRENDERING_ENABLED = 1,
WCA_NCRENDERING_POLICY = 2,
WCA_TRANSITIONS_FORCEDISABLED = 3,
WCA_ALLOW_NCPAINT = 4,
WCA_CAPTION_BUTTON_BOUNDS = 5,
WCA_NONCLIENT_RTL_LAYOUT = 6,
WCA_FORCE_ICONIC_REPRESENTATION = 7,
WCA_EXTENDED_FRAME_BOUNDS = 8,
WCA_HAS_ICONIC_BITMAP = 9,
WCA_THEME_ATTRIBUTES = 10,
WCA_NCRENDERING_EXILED = 11,
WCA_NCADORNMENTINFO = 12,
WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
WCA_VIDEO_OVERLAY_ACTIVE = 14,
WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
WCA_DISALLOW_PEEK = 16,
WCA_CLOAK = 17,
WCA_CLOAKED = 18,
WCA_ACCENT_POLICY = 19,
WCA_FREEZE_REPRESENTATION = 20,
WCA_EVER_UNCLOAKED = 21,
WCA_VISUAL_OWNER = 22,
WCA_HOLOGRAPHIC = 23,
WCA_EXCLUDED_FROM_DDA = 24,
WCA_PASSIVEUPDATEMODE = 25,
WCA_USEDARKMODECOLORS = 26,
WCA_CORNER_STYLE = 27,
WCA_PART_COLOR = 28,
WCA_DISABLE_MOVESIZE_FEEDBACK = 29,
WCA_LAST = 30
} WINDOWCOMPOSITIONATTRIB;
typedef struct _WINDOWCOMPOSITIONATTRIBDATA
{
WINDOWCOMPOSITIONATTRIB Attrib;
PVOID pvData;
SIZE_T cbData;
} WINDOWCOMPOSITIONATTRIBDATA;
typedef enum _ACCENT_STATE
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, // RS4 1803
ACCENT_ENABLE_HOSTBACKDROP = 5, // RS5 1809
ACCENT_INVALID_STATE = 6
} ACCENT_STATE;
typedef struct _ACCENT_POLICY
{
ACCENT_STATE AccentState;
DWORD AccentFlags;
DWORD GradientColor;
DWORD AnimationId;
} ACCENT_POLICY;
typedef BOOL (WINAPI *pfnGetWindowCompositionAttribute)(HWND, WINDOWCOMPOSITIONATTRIBDATA*);
typedef BOOL (WINAPI *pfnSetWindowCompositionAttribute)(HWND, WINDOWCOMPOSITIONATTRIBDATA*);
@KitsuneAlex
Copy link

Very useful, thanks a bunch! <3

@Qix-
Copy link

Qix- commented Dec 26, 2020

Any reason why the ACCENT_ENABLE_ACRYLICBLURBEHIND setting would cause immense performance dropoff? I can't find any information as to how to improve that.

@KitsuneAlex
Copy link

It is an internal function which emulates the behaviour of the AcrylicBrush from the new WinUI toolkit. For some reason it has these performance issues and is only used for the taskbar, which makes it go by unnoticed since the taskbar is static. I've been waiting for a couple of windows builds now since over a year and this hasn't been adressed yet sadly. I was looking into WinUI and found a way to couple WinUI with a classic Win32 application, which worked nicely, the only thing that didn't work tho was the looked after AcrylicBrush which depends on the HostBackdropBrush (you can look all of these up on MSDN) :/

@Qix-
Copy link

Qix- commented Feb 2, 2021

@KitsuneAlex that makes sense, thanks for the information. I wish M$ would give us an API to do it nicely :/

@HackerDaGreat57
Copy link

This is amazing, thank you so much!

@KitsuneAlex
Copy link

I heard rumors that this works on Windows 11 again? I will give this a try later and give a little update with some information if it works :)

@HackerDaGreat57
Copy link

It works for me. (Windows 11 Build 22000)

@KitsuneAlex
Copy link

NICE ONE! Time to uncomment that code :^)

@like-me
Copy link

like-me commented Jan 29, 2023

I'd like to know what WINDOWCOMPOSITIONATTRIB enumerations can do. Is there any documentation on that?

@HackerDaGreat57
Copy link

@like-me there is no public documentation on this which is why this gist exists :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment