博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF Aero Glass Window
阅读量:6163 次
发布时间:2019-06-21

本文共 4132 字,大约阅读时间需要 13 分钟。

原文:

  1. 用法

    1. Win7 
    2. Win10 SetWindowCompositionAttribute
  2. 代码
    1. 1 using System;  2 using System.Collections.Generic;  3 using System.Linq;  4 using System.Runtime.InteropServices;  5 using System.Text;  6 using System.Threading.Tasks;  7 using System.Windows;  8 using System.Windows.Interop;  9  10 namespace AeroWindow 11 { 12     internal static class NativeMethods 13     { 14         [DllImport("user32.dll")] 15         internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttribData data); 16  17         [StructLayout(LayoutKind.Sequential)] 18         internal struct WindowCompositionAttribData 19         { 20             public WindowCompositionAttribute Attribute; 21             public IntPtr Data; 22             public int SizeOfData; 23         } 24  25         [StructLayout(LayoutKind.Sequential)] 26         internal struct AccentPolicy 27         { 28             public AccentState AccentState; 29             public AccentFlags AccentFlags; 30             public int GradientColor; 31             public int AnimationId; 32         } 33  34         [Flags] 35         internal enum AccentFlags 36         { 37             // ...  38             DrawLeftBorder = 0x20, 39             DrawTopBorder = 0x40, 40             DrawRightBorder = 0x80, 41             DrawBottomBorder = 0x100, 42             DrawAllBorders = (DrawLeftBorder | DrawTopBorder | DrawRightBorder | DrawBottomBorder) 43             // ...  44         } 45  46         internal enum WindowCompositionAttribute 47         { 48             // ...  49             WCA_ACCENT_POLICY = 19 50             // ...  51         } 52  53         internal enum AccentState 54         { 55             ACCENT_DISABLED = 0, 56             ACCENT_ENABLE_GRADIENT = 1, 57             ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, 58             ACCENT_ENABLE_BLURBEHIND = 3, 59             ACCENT_INVALID_STATE = 4 60         } 61  62         public static void EnableBlur(this Window window) 63         { 64             if (SystemParameters.HighContrast) 65             { 66                 return; // Blur is not useful in high contrast mode  67             } 68             SetAccentPolicy(window, NativeMethods.AccentState.ACCENT_ENABLE_BLURBEHIND); 69         } 70  71  72         public static void DisableBlur(this Window window) 73         { 74             SetAccentPolicy(window, NativeMethods.AccentState.ACCENT_DISABLED); 75         } 76  77         private static void SetAccentPolicy(Window window, NativeMethods.AccentState accentState) 78         { 79             var windowHelper = new WindowInteropHelper(window); 80             var accent = new NativeMethods.AccentPolicy 81             { 82                 AccentState = accentState, 83                 AccentFlags = GetAccentFlagsForTaskbarPosition(), 84                   AnimationId = 2 85             }; 86             var accentStructSize = Marshal.SizeOf(accent); 87             var accentPtr = Marshal.AllocHGlobal(accentStructSize); 88             Marshal.StructureToPtr(accent, accentPtr, false); 89             var data = new NativeMethods.WindowCompositionAttribData 90             { 91                 Attribute = NativeMethods.WindowCompositionAttribute.WCA_ACCENT_POLICY, 92                 SizeOfData = accentStructSize, 93                 Data = accentPtr 94             }; 95             NativeMethods.SetWindowCompositionAttribute(windowHelper.Handle, ref data); 96             Marshal.FreeHGlobal(accentPtr); 97         } 98  99         private static NativeMethods.AccentFlags GetAccentFlagsForTaskbarPosition()100         {101             return NativeMethods.AccentFlags.DrawAllBorders;102         }103     }104  }

       

      1  public MainWindow() 2         { 3             RoutedEventHandler handler = null; 4             handler = (s, e) => 5             { 6                 Loaded -= handler; 7                 this.EnableBlur(); 8             }; 9             Loaded += handler;10 11             InitializeComponent();12         }
      1 
      11
      12
      13
      14
      15

       

  3. 效果

  

 

转载地址:http://tarfa.baihongyu.com/

你可能感兴趣的文章
Cause: java.sql.SQLException: The user specified as a definer ('root'@'%') does not exist
查看>>
quratz线程
查看>>
execnet: rapid multi-Python deployment
查看>>
windows修改3389端口
查看>>
关于JavaScript词法
查看>>
FreeSwitch中的会议功能(4)
查看>>
MySQL中创建用户分配权限(到指定数据库或者指定数据库表中)
查看>>
AutoReleasePool 和 ARC 以及Garbage Collection
查看>>
重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础
查看>>
乐在其中设计模式(C#) - 提供者模式(Provider Pattern)
查看>>
MVP Community Camp 社区大课堂
查看>>
GWT用frame调用JSP
查看>>
大型高性能ASP.NET系统架构设计
查看>>
insert select带来的问题
查看>>
EasyUI 添加tab页(iframe方式)
查看>>
mysqldump主要参数探究
查看>>
好记心不如烂笔头,ssh登录 The authenticity of host 192.168.0.xxx can't be established. 的问题...
查看>>
使用addChildViewController手动控制UIViewController的切换
查看>>
Android Fragment应用实战
查看>>
SQL Server查询死锁并KILL
查看>>