Exemplo n.º 1
0
        public static void Apply(Window window, Color backgroundColor, AccentState state = AccentState.AcrylicBlurBehind)
        {
            int getColorCode(Color color)
            {
                return(color.A << 24 | // DWM uses ABGR format
                       color.B << 16 |
                       color.G << 8 |
                       color.R);
            }

            var helper     = new WindowInteropHelper(window);
            var accent     = new AccentPolicy();
            var accentSize = Marshal.SizeOf(accent);

            accent.AccentState   = state;
            accent.GradientColor = getColorCode(backgroundColor);
            var accentPointer = Marshal.AllocHGlobal(accentSize);

            Marshal.StructureToPtr(accent, accentPointer, false);
            var data = new WindowsCompostionAttributeData
            {
                Attribute  = 19, //WindowCompositionAttribute.AccentPolicy
                SizeOfData = accentSize,
                Data       = accentPointer,
            };

            SetWindowCompositionAttribute(helper.Handle, ref data);
            Marshal.FreeHGlobal(accentPointer);
        }
Exemplo n.º 2
0
 private static extern int SetWindowCompositionAttribute(IntPtr hWnd, ref WindowsCompostionAttributeData data);