public static void DisableWin7ExtendAeroGlass(Visual visual) { try { // 为WPF程序获取窗口句柄 //var windowInteropHelper = new WindowInteropHelper(obj); //IntPtr handle = windowInteropHelper.Handle; var visualHelperIntPtr = ((HwndSource)PresentationSource.FromVisual(visual)).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd(visualHelperIntPtr); var bb = new DwmBlurbehind { dwFlags = CoreNativeMethods.DwmBlurBehindDwFlags.DwmBbEnable, Enabled = false }; DwmEnableBlurBehindWindow(visualHelperIntPtr, ref bb); const int dwmwaNcrenderingPolicy = 2; var dwmncrpDisabled = 2; DwmSetWindowAttribute(visualHelperIntPtr, dwmwaNcrenderingPolicy, ref dwmncrpDisabled, sizeof(int)); } catch (Exception) { Application.Current.MainWindow.Background = Brushes.White; } }
protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); var bb = new DwmBlurbehind { dwFlags = CoreNativeMethods.DwmBlurBehindDwFlags.DwmBbEnable, Enabled = true }; WindowStartupLocation = WindowStartupLocation.CenterScreen; Background = Brushes.Transparent; ResizeMode = ResizeMode.NoResize; //WindowStyle = WindowStyle.None; Focus(); var hwnd = new WindowInteropHelper(this).Handle; HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent; DwmEnableBlurBehindWindow(hwnd, ref bb); const int dwmwaNcrenderingPolicy = 2; var dwmncrpDisabled = 2; DwmSetWindowAttribute(hwnd, dwmwaNcrenderingPolicy, ref dwmncrpDisabled, sizeof(int)); }
private readonly uint _blurBackgroundColor = 0x550000; /* BGR color format */ internal void Blur(bool enable = true) { var WinBuild = NativeMethods.WinBuild(); if (WinBuild == 7600 || WinBuild == 7601) { var bb = new DwmBlurbehind { dwFlags = DwmBlurBehindDwFlags.DwmBbEnable, Enabled = true }; var hwnd = new WindowInteropHelper(this).Handle; HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent; DwmEnableBlurBehindWindow(hwnd, ref bb); const int dwmwaNcrenderingPolicy = 2; var dwmncrpDisabled = 2; DwmSetWindowAttribute(hwnd, dwmwaNcrenderingPolicy, ref dwmncrpDisabled, sizeof(int)); } else if (WinBuild >= 17134) { var windowHelper = new WindowInteropHelper(this); var accent = new AccentPolicy { AccentState = (enable) ? AccentState.ACCENT_ENABLE_BLURBEHIND : AccentState.ACCENT_DISABLED, AccentFlags = AccentFlags.DrawNoBorder, GradientColor = (_blurOpacity << 24) | (_blurBackgroundColor & 0xFFFFFF), AnimationId = 0 }; 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(System.Windows.Forms.Form targetForm, bool keepBG = false) { string OSName = Leayal.OSVersionInfo.Name; if (OSName == "Windows 10") { var accent = new AccentPolicy(); accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND; var accentStructSize = Marshal.SizeOf(accent); 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(targetForm.Handle, ref data); Marshal.FreeHGlobal(accentPtr); if (!keepBG) { targetForm.BackColor = Color.Lavender; targetForm.TransparencyKey = Color.Lavender; } //targetForm.Paint += TargetForm_Paint; } else if (OSName == "Windows 7") { var hr = CreateEllipticRgn(0, 0, targetForm.Width, targetForm.Height); var dbb = new DwmBlurbehind { FEnable = true, DwFlags = 1, HRgnBlur = hr, FTransitionOnMaximized = false }; DwmEnableBlurBehindWindow(targetForm.Handle, ref dbb); if (!keepBG) { targetForm.BackColor = Color.Black; } targetForm.Paint += TargetForm_Paint; } }
public static extern void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DwmBlurbehind blurBehind);
private static extern int DwmEnableBlurBehindWindow(IntPtr hWnd, ref DwmBlurbehind pBlurBehind);
internal static extern void DwmEnableBlurBehindWindow(IntPtr hWnd, DwmBlurbehind pBlurBehind);
public static extern void DwmEnableBlurBehindWindow( IntPtr windowHandle, ref DwmBlurbehind blurBehind );
public static extern void DwmEnableBlurBehindWindow(IntPtr windowHandle, ref DwmBlurbehind blurBehind);
public static extern void DwmEnableBlurBehindWindow(IntPtr hWnd, DwmBlurbehind pBlurBehind);