原文:WPF Aero Glass Window

  1. 用法

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

      1. 1 public MainWindow()
      2. 2 {
      3. 3 RoutedEventHandler handler = null;
      4. 4 handler = (s, e) =>
      5. 5 {
      6. 6 Loaded -= handler;
      7. 7 this.EnableBlur();
      8. 8 };
      9. 9 Loaded += handler;
      10. 10
      11. 11 InitializeComponent();
      12. 12 }
      1. 1 <Window x:Class="AeroWindow.MainWindow"
      2. 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      3. 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      4. 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      5. 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      6. 6 xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
      7. 7 xmlns:local="clr-namespace:AeroWindow"
      8. 8 mc:Ignorable="d"
      9. 9 Background="#44E6ECF0"
      10. 10 Title="MainWindow" Height="600" Width="800" >
      11. 11 <shell:WindowChrome.WindowChrome>
      12. 12 <shell:WindowChrome GlassFrameThickness="1" UseAeroCaptionButtons="False" NonClientFrameEdges="None" CornerRadius="10" CaptionHeight="600" />
      13. 13 </shell:WindowChrome.WindowChrome>
      14. 14 <Grid/>
      15. 15 </Window>
  3. 效果

  

WPF Aero Glass Window的更多相关文章

  1. Windows 7 扩展玻璃效果(Aero Glass)

    转自:http://www.cnblogs.com/gnielee/archive/2010/10/04/windows7-extend-aero-glass.html Windows 7 操作系统默 ...

  2. 【转】MFC 迅雷七窗体特效,使用DWM实现Aero Glass效果

    从Windows Vista开始,Aero Glass效果被应用在了Home Premium以上的系统中(Home Basic不具有该效果).这种效果是由DWM(Desktop Window Mana ...

  3. 窗口玻璃特效,半透明窗口,使用DWM实现Aero Glass效果

    转自:http://blog.csdn.net/ntwilford/article/details/5656633 从Windows Vista开始,Aero Glass效果被应用在了Home Pre ...

  4. C# WPF 多个window 相互覆盖的次序控制 不用topmost

    原文:C# WPF 多个window 相互覆盖的次序控制 不用topmost   WindowInteropHelper mianHanel = new WindowInteropHelper(Mai ...

  5. WPF 不要给 Window 类设置变换矩阵(分析篇):System.InvalidOperationException: 转换不可逆。

    原文:WPF 不要给 Window 类设置变换矩阵(分析篇):System.InvalidOperationException: 转换不可逆. 最近总是收到一个异常 "System.Inva ...

  6. WPF 不要给 Window 类设置变换矩阵(应用篇)

    原文:WPF 不要给 Window 类设置变换矩阵(应用篇) WPF 的 Window 类是不允许设置变换矩阵的.不过,总会有小伙伴为了能够设置一下试图绕过一些验证机制. 不要试图绕过,因为你会遇到更 ...

  7. WPF直接用Window.Close直接关闭窗口导致不能完全退出的问题

    前几天我在CSDN扔了一个问题,基本描述一下:写了一段这样的代码,来实现获取Control的template,却发现一个这样的问题,就是当我打开了一个window以后,手动调用Close(),窗口的确 ...

  8. WPF 中保存 window(窗口)或者canvas成图片

    最近需要用到这个功能,搜了一下不少代码有问题 ,找到一个效果比较好的,支持多级子元素 记一下. private void button_save_window_Click(object sender, ...

  9. wpf 只在window是ShowDialog打开时才设置DialogResult

    //only set DialogResult when window is ShowDialog before if(System.Windows.Interop.ComponentDispatch ...

随机推荐

  1. Python实战:如何隐藏自己的爬虫身份

    使用爬虫访问网站,需要尽可能的隐藏自己的身份,以防被服务器屏蔽,在工作工程中,我们有2种方式来实现这一目的,分别是延时访问和动态代理,接下来我们会对这两种方式进行讲解 1.延时访问 见名之意,延时访问 ...

  2. jQuery+ localStorage 实现一个简易的计时器

    原型 图片发自简书App 需求1.关闭浏览器时时间继续运行2.刷新时保持当前状态3.结束时间保存在客户端 <div class="wrapper"> <div c ...

  3. sparksql parquet 合并元数据

    java public class ParquetMergeSchema { private static SparkConf conf = new SparkConf().setAppName(&q ...

  4. MySQL实现类似Oracle中的nextval和currval

    CREATE TABLE `sequence` ( `seq_name` varchar(50) NOT NULL, `current_val` int(11) NOT NULL, `incremen ...

  5. React父子组件的一个混淆点

    反正我自己是混淆了,React父子组件和组件类的继承弄混在一起了.这两个东西完全是不相关的. 父子组件可以看成两个组件标签的包含关系,在另外一个组件标签的内部就是子组件,父子组件通过这种关系通信. 组 ...

  6. IO 字符流学习

    import java.awt.Frame; import java.io.*; public class filewriter { /** * @param args */ public stati ...

  7. CMake生成OpenCV解决方案&&编译OpenCV源码

    生成OpenCV工程需要用到CMake,所以第一步需要下载CMake软件,下载链接:CMake下载 目前最新的版本是3.7.1,这里选择下载Platform下的Windows win32-x86 ZI ...

  8. 微信公众平台自定义菜单接口API指南

    微信公众平台开发模式自定义菜单接口API指南 简介 开发者获取使用凭证(如何获取凭证)后,可以使用该凭证对公众账号的自定义菜单进行创建.查询和删除等操作. 自定义菜单接口可实现以下类型按钮: clic ...

  9. JS 禁止IE用右键

    <!--组合键: -->IE的键盘监听最多只能作用于document上(window我试过不行)如果内嵌了iframe并且你的焦点在iframe上,那么按键无效 这里我用CTRL+Q写的例 ...

  10. 用WPF窗体打造个性化界面的图片浏览器

    原文:用WPF窗体打造个性化界面的图片浏览器 本文使用WPF窗体(XAML及C#)与Win Form控件(FolderBrowserDialog)结合的方式, 演示制作了一个简易漂亮的WPF图片浏览器 ...