internal static void EnableBlur(AccentState acc, Window win) { WindowInteropHelper windowHelper = new WindowInteropHelper(win); AccentPolicy accent = new AccentPolicy { AccentState = acc }; int accentStructSize = Marshal.SizeOf(accent); IntPtr accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); WindowCompositionAttributeData data = new WindowCompositionAttributeData { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; SetWindowCompositionAttribute(windowHelper.Handle, ref data); Marshal.FreeHGlobal(accentPtr); }
public static void SetAccentState(IntPtr wind, AccentState state, Color?col = null) { col = col ?? Themes.CurrentConfiguration.GetAccentColour(); if (state == AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND && !OSVersion.IsWindows10AprilUpdate) { state = AccentState.ACCENT_ENABLE_BLURBEHIND; } var accent = new AccentPolicy { AccentState = state, GradientColor = (uint)((col.Value.A << 24) | ((col.Value.B << 16 | col.Value.G << 8 | col.Value.R) & 0xFFFFFF)) }; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; SetWindowCompositionAttribute(wind, ref data); Marshal.FreeHGlobal(accentPtr); }
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); }
internal static void SetAccentPolicy(IntPtr hWnd, AccentState accentState, AccentFlags accentFlags, uint gradientColor) { var accent = new AccentPolicy { AccentState = accentState, AccentFlags = accentFlags, AnimationId = 0, GradientColor = gradientColor }; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; _SetWindowCompositionAttribute(hWnd, ref data); Marshal.FreeHGlobal(accentPtr); }
public static void DisableBlur(IntPtr hWnd, AccentState accentState, AccentFlags flags, UsingColors gradientColor) { var hex = (uint)gradientColor; NativeMethods.SetAccentPolicy(hWnd, accentState, flags, hex); }
public AccentPolicy(AccentState accentState, int accentFlags, int gradientColor, int animationId) { AccentState = accentState; AccentFlags = accentFlags; GradientColor = gradientColor; AnimationId = animationId; }
/// <summary> /// Gracefully allows managed code to easily call SetWindowCompositionAttribute without messing with memory and unsigned integers. /// </summary> /// <remarks> /// If the target window uses system window decorations, the accent policy will bleed over the edges of the decoration. /// </remarks> /// <param name="hWnd"> /// The target window's handle. /// </param> /// <param name="state"> /// The accent state to apply. /// </param> /// <param name="color"> /// The value of GradientColor. Will default to 0x00FFFFFF. /// </param> /// <seealso cref="AccentState"/> public static void SetWindowCompositionAttribute(IntPtr hWnd, AccentState state = AccentState.ACCENT_ENABLE_BLURBEHIND, SolidColorBrush color = null) { if (color == null) { color = Brushes.Transparent; } var hexColor = (uint)((color.Color.A << 24) + (color.Color.B << 16) + (color.Color.G << 8) + color.Color.R); var accent = new AccentPolicy() { AccentState = state, AccentFlags = 2, GradientColor = hexColor }; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData() { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, Data = accentPtr, SizeOfData = accentStructSize }; SetWindowCompositionAttribute(hWnd, ref data); Marshal.FreeHGlobal(accentPtr); }
public static void Set(Window window, AccentState accentState, AccentFlags accentFlags) { var hwndSource = PresentationSource.FromVisual(window) as HwndSource; if (hwndSource == null) { return; } var accent = new AccentPolicy { AccentState = accentState, AccentFlags = accentFlags, }; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr, }; User32.SetWindowCompositionAttribute(hwndSource.Handle, ref data); Marshal.FreeHGlobal(accentPtr); }
private void SetWindowAccent(Window w, AccentState state) { var windowHelper = new WindowInteropHelper(w); windowHelper.EnsureHandle(); var accent = new AccentPolicy { AccentState = state }; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; SetWindowCompositionAttribute(windowHelper.Handle, ref data); Marshal.FreeHGlobal(accentPtr); }
public static void EnableBlur(IntPtr hWnd, AccentState accentState, uint hex) { if (SystemParameters.HighContrast) { return; // Blur is not useful in high contrast mode } NativeMethods.SetAccentPolicy(hWnd, accentState, AccentFlags.None, hex); }
/// <summary> /// 设置控件效果 /// </summary> public static bool SetBlur(IntPtr hwnd, AccentState state) { try { EnableBlur(hwnd, state); return(true); } catch { return(false); } }
public static void SetAccentState(string taskbar, AccentState state) { if (taskbar == "Main") { TT.Options.Settings.MainTaskbarStyle.AccentState = (byte)state; } else { TT.Options.Settings.MaximizedTaskbarStyle.AccentState = (byte)state; } }
/// <summary> /// check if platform /// </summary> /// <param name="state"></param> /// <returns></returns> internal static AccentState CheckPlatformSupport(AccentState state) { var currentVersion = SystemInfo.SystemInfo.Version.Value; if (currentVersion >= VersionInfo.Windows101903) { if (state == AccentState.ACCENT_DISABLED) { return(AccentState.ACCENT_ENABLE_BLURBEHIND); } if (state >= AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND) { return(AccentState.ACCENT_ENABLE_BLURBEHIND); } } if (currentVersion == VersionInfo.Windows101809) { if (state == AccentState.ACCENT_DISABLED) { return(AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND); } } if (currentVersion >= VersionInfo.Windows10) { if (state == AccentState.ACCENT_DISABLED) { return(AccentState.ACCENT_ENABLE_BLURBEHIND); } if (state >= AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND) { return(AccentState.ACCENT_ENABLE_BLURBEHIND); } } if (currentVersion >= VersionInfo.Windows7) { if (state == AccentState.ACCENT_DISABLED) { return(AccentState.ACCENT_ENABLE_TRANSPARENTGRADIENT); } if (state >= AccentState.ACCENT_ENABLE_BLURBEHIND) { return(AccentState.ACCENT_ENABLE_TRANSPARENTGRADIENT); } } return(state); }
public static void BlurWindow(Window win, AccentState state) { AccentPolicy accent = new AccentPolicy(); accent.AccentState = state; int accentStructSize = Marshal.SizeOf(accent); IntPtr accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); WindowCompositionAttributeData data = new WindowCompositionAttributeData(); data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY; data.SizeOfData = accentStructSize; data.Data = accentPtr; WinAPI.SetWindowCompositionAttribute(new WindowInteropHelper(win).Handle, ref data); Marshal.FreeHGlobal(accentPtr); }
internal static AccentState SelectAccentState(AcrylicAccentState state = AcrylicAccentState.Default) { // ウィンドウのアクリル効果を設定する AccentState value = state switch { // ウィンドウ背景のぼかしを行うのはWindows10の場合のみ // OSのバージョンに従い、AccentStateを切り替える AcrylicAccentState.Default => SystemInfo.Version.Value switch { // Windows11環境ではアクリル効果を無効にする var version when version >= VersionInfos.Windows11_Preview => AccentState.ACCENT_ENABLE_GRADIENT, // Windows10 1903以降では、ACCENT_ENABLE_ACRYLICBLURBEHINDを用いると、ウィンドウのドラッグ移動などでマウス操作に追従しなくなる。 // ウィンドウの移動/リサイズ中だけ、ACCENT_ENABLE_ACRYLICBLURBEHINDを無効にして、この問題を回避する //var version when version >= VersionInfos.Windows10_1903 => AccentState.ACCENT_ENABLE_BLURBEHIND, var version when version >= VersionInfos.Windows10_1809 => AccentState.ACCENT_ENABLE_ACRYLICBLURBEHIND, var version when version >= VersionInfos.Windows10 => AccentState.ACCENT_ENABLE_BLURBEHIND, _ => AccentState.ACCENT_ENABLE_TRANSPARENTGRADIENT, },
public static void SetBlur(FrameworkElement element, AccentState value) { //由于某些原因在我的vs和net版本下 如果此方法的名称为 SetBlurProperty 则可以起作用, //但在xaml中对应的属性名称就会变成"BlurProperty",否则在Xaml下设置Blur属性值时此方法不会 //触发,因此只能在OnBlurChanged中更改此方法 try { IntPtr hwnd = IntPtr.Zero; if (element.IsInitialized) { hwnd = GetVisualHandle(element); EnableBlur(hwnd, value); } else { element.Loaded += (s, e) => { hwnd = GetVisualHandle(element); EnableBlur(hwnd, value); }; } } catch { } }
/// <summary> /// 给句柄指定的控件设置毛玻璃效果 /// </summary> internal static void EnableBlur(IntPtr hwnd, AccentState state) { var accent = new AccentPolicy { AccentState = state }; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; SetWindowCompositionAttribute(hwnd, ref data); Marshal.FreeHGlobal(accentPtr); }
static void SetAccentPolicy(System.Windows.Window window, AccentState state) { var windowHelper = new WindowInteropHelper(window); var accent = new AccentPolicy(); var accentStructSize = Marshal.SizeOf(accent); accent.AccentState = state; var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData(); data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY; data.SizeOfData = accentStructSize; data.Data = accentPtr; SetWindowCompositionAttribute(windowHelper.Handle, ref data); Marshal.FreeHGlobal(accentPtr); }
private static void ChangeComposition(Window w, AccentState state) { var accent = new AccentPolicy { AccentState = state, AccentFlags = 2, GradientColor = 0x00FFFFFF, }; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr, }; SetWindowCompositionAttribute(new WindowInteropHelper(w).Handle, ref data); Marshal.FreeHGlobal(accentPtr); }
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); }
//to call blur in our desired window internal WindowBlureffect(Window window, AccentState accentState) { this.window = window; this.accentState = accentState; EnableBlur(); }
/// <summary> /// Provides a shorthand for SetWindowCompositionAttribute on XAML windows. /// </summary> /// <remarks> /// If the target window uses system window decorations, the accent policy will bleed over the edges of the decoration. /// </remarks> /// <param name="state"> /// The accent state to apply. /// </param> /// <param name="color"> /// The value of GradientColor. Will default to 0x00FFFFFF. /// </param> /// <seealso cref="SetWindowCompositionAttribute(IntPtr, AccentState, SolidColorBrush)"/> /// <seealso cref="AccentState"/> public static void SetCompositionAttribute(this Window window, AccentState state = AccentState.ACCENT_ENABLE_BLURBEHIND, SolidColorBrush color = null) => SetWindowCompositionAttribute(new WindowInteropHelper(window).Handle, state, color);
private void SetWindowAccent(Window wind, AccentState themeAccentMode) { var windowHelper = new WindowInteropHelper(wind); var accent = new AccentPolicy { AccentState = themeAccentMode }; var accentStructSize = Marshal.SizeOf(accent); var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; SetWindowCompositionAttribute(windowHelper.Handle, ref data); Marshal.FreeHGlobal(accentPtr); }
public static void SetAccentState(AccentState state) { SetAccentState(TaskbarBeingEdited, state); }
/// <summary> /// Enable blur effect in windows platform /// </summary> /// <param name="hwnd"></param> /// <param name="style"></param> /// <param name="state"></param> /// <param name="accentColor"></param> internal static void EnableBlur(IntPtr hwnd, uint accentColor = AccentColor, AccentFlagsType style = AccentFlagsType.Window, AccentState state = AccentState.ACCENT_DISABLED) { var accent = new AccentPolicy(); var accentStructSize = Marshal.SizeOf(accent); accent.AccentState = state == AccentState.ACCENT_DISABLED ? CheckPlatformSupport(state) : state; accent.AccentFlags = style == AccentFlagsType.Window ? 2 : 0x20 | 0x40 | 0x80 | 0x100; accent.GradientColor = accentColor; var accentPtr = Marshal.AllocHGlobal(accentStructSize); Marshal.StructureToPtr(accent, accentPtr, false); var data = new WindowCompositionAttributeData { Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, SizeOfData = accentStructSize, Data = accentPtr }; _ = SetWindowCompositionAttribute(hwnd, ref data); Marshal.FreeHGlobal(accentPtr); }