Skip to content

Instantly share code, notes, and snippets.

@xv
Created November 5, 2020 20:05
Show Gist options
  • Save xv/43bd4c944202a593ac8ec6daa299b471 to your computer and use it in GitHub Desktop.
Save xv/43bd4c944202a593ac8ec6daa299b471 to your computer and use it in GitHub Desktop.
Undocumented API for Windows 10 Acrylic style.
internal enum WindowCompositionAttribute
{
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_LAST = 26
}
internal enum AccentState
{
ACCENT_DISABLED = 0,
ACCENT_ENABLE_GRADIENT = 1,
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
ACCENT_ENABLE_BLURBEHIND = 3,
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4, // RS4 1803.17063
ACCENT_ENABLE_HOSTBACKDROP = 5, // RS5 1809
ACCENT_INVALID_STATE = 6
}
[StructLayout(LayoutKind.Sequential)]
internal struct WINCOMPATTRDATA
{
internal WindowCompositionAttribute attribute;
internal IntPtr pData;
internal int cbSize;
}
[StructLayout(LayoutKind.Sequential)]
internal struct ACCENTPOLICY
{
internal AccentState accentState;
internal int accentFlags;
internal uint gradientColor;
internal int animationId;
}
[DllImport("user32.dll")]
internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WINCOMPATTRDATA pAttrData);
private uint ColorToAbgr(Color color)
{
return ((uint)color.A << 24) |
((uint)color.B << 16) | ((uint)color.G << 8) | color.R;
}
public int SetWindows10Acrylic(IntPtr hWnd)
{
var result = 0;
var accent = new ACCENTPOLICY
{
accentState = AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND,
accentFlags = 0,
gradientColor = ColorToAbgr(Color.FromArgb(5, Color.Black)),
animationId = 0
};
var accentSize = Marshal.SizeOf(accent);
var accentPtr = Marshal.AllocHGlobal(accentSize);
try
{
Marshal.StructureToPtr(accent, accentPtr, false);
var compData = new WINCOMPATTRDATA
{
attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
pData = accentPtr,
cbSize = accentSize
};
result = SetWindowCompositionAttribute(hWnd, ref compData);
}
finally
{
Marshal.FreeHGlobal(accentPtr);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment