Beispiel #1
0
        public static void enableDarkTitlebar(IntPtr handle, bool dark)
        {
            AllowDarkModeForWindow(handle, dark);
            int    sizeOfData = Marshal.SizeOf(dark);
            IntPtr dataPtr    = Marshal.AllocHGlobal(sizeOfData);

            WindowCompositionAttribData data = new WindowCompositionAttribData
            {
                Attribute  = WindowCompositionAttribute.WCA_USEDARKMODECOLORS,
                Data       = dataPtr,
                SizeOfData = sizeOfData
            };

            SetWindowCompositionAttribute(handle, ref data);

            Marshal.FreeHGlobal(dataPtr);
        }
Beispiel #2
0
        static bool SetAccentPolicy(Window window, AccentState accentState)
        {
            var windowHelper = new WindowInteropHelper(window);
            var accent       = new AccentPolicy
            {
                AccentState = accentState,
                AccentFlags = GetAccentFlagsForTaskbarPosition(),
                AnimationId = 3
            };
            var accentStructSize = Marshal.SizeOf(accent);
            var accentPtr        = Marshal.AllocHGlobal(accentStructSize);

            Marshal.StructureToPtr(accent, accentPtr, false);
            var data = new WindowCompositionAttribData
            {
                Attribute  = WindowCompositionAttribute.WCA_ACCENT_POLICY,
                SizeOfData = accentStructSize,
                Data       = accentPtr
            };
            var result = NativeMethods.SetWindowCompositionAttribute(windowHelper.Handle, ref data);

            Marshal.FreeHGlobal(accentPtr);
            return(result);
        }
        public static bool SetAeroGlass(this Window window, bool enable)
        {
            if (window == null)
                throw new ArgumentNullException(nameof(window));

            if (Environment.OSVersion.Version.Major < 6)
            {
                // An OS older than Windows Vista.
                return false;
            }

            if (SystemParameters.HighContrast)
            {
                // Blur is not useful in high contrast mode.
                return false;
            }

            try
            {
                var windowHelper = new WindowInteropHelper(window);

                var accent = new AccentPolicy
                {
                    AccentState = enable ? AccentState.ACCENT_ENABLE_BLURBEHIND : AccentState.ACCENT_DISABLED,
                    //AccentFlags = AccentFlags.DrawAllBorders
                };

                var accentStructSize = Marshal.SizeOf(accent);
                var accentPtr = Marshal.AllocHGlobal(accentStructSize);
                Marshal.StructureToPtr(accent, accentPtr, false);

                var data = new WindowCompositionAttribData
                {
                    Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
                    SizeOfData = accentStructSize,
                    Data = accentPtr
                };

                SetWindowCompositionAttribute(windowHelper.Handle, ref data);

                Marshal.FreeHGlobal(accentPtr);
            }
            catch (DllNotFoundException)
            {
                return false;
            }

            return true;
        }
 internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttribData data);
Beispiel #5
0
 internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttribData data);
 private static extern bool SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttribData data);