WPF Aero Glass Window
原文:WPF Aero Glass Window

  1. 用法

    1. Win7 DwmSetWindowAttribute function
    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 <Window x:Class="AeroWindow.MainWindow"
       2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       5         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       6         xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell"
       7         xmlns:local="clr-namespace:AeroWindow"
       8         mc:Ignorable="d"
       9         Background="#44E6ECF0"
      10         Title="MainWindow" Height="600" Width="800" >
      11     <shell:WindowChrome.WindowChrome>
      12         <shell:WindowChrome GlassFrameThickness="1" UseAeroCaptionButtons="False"  NonClientFrameEdges="None"  CornerRadius="10" CaptionHeight="600"   />
      13     </shell:WindowChrome.WindowChrome>
      14     <Grid/>
      15 </Window>

  3. 效果

  

posted on 2017-12-04 01:00 NET未来之路 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/7968530.html

WPF Aero Glass Window相关推荐

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

    Windows 7 操作系统默认具有一款玻璃效果主题(Aero Glass).如果选择了该款主题,所有的应用程序标题栏都会处于玻璃透明效果(如下图).这个功能是由Desktop Window Mana ...

  2. 计算机的aero界面是一种,Win8桌面UI大变脸 去除Aero Glass等特效

    在Windows 8话题中,谈论最多的莫过于其Metro用户界面和触摸操作为重点的设计,很多人认为微软这一步跨地太大了.今天,在官方博客中,微软介绍了改进Windows 8用户界面的更多决定. 首先, ...

  3. C#迅雷七窗体特效,使用DWM实现Aero Glass效果

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

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

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

  5. aero glass_我的Vista Aero Glass自行关闭,如何再次启用它?

    aero glass A reader wrote in yesterday asking why she no longer had the "pretty" glass win ...

  6. 解决WPF中重载Window.OnRender函数失效问题

    原文:解决WPF中重载Window.OnRender函数失效问题 今天实验一个绘图算法的时候,偶然发现重载Window.OnRender的方法是没有效果的. public partial class ...

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

    C# WPF 多个window 相互覆盖的次序控制 不用topmost 原文:C# WPF 多个window 相互覆盖的次序控制 不用topmost WindowInteropHelper mianH ...

  8. java aero_java – 结合Aero Glass效果和SWT

    作为一个宠物项目,我一直在玩将Aero Glass效果集成到我的SWT应用程序中的概念. Łukasz Milewski has an excellent blog post解释了如何实现这一点,这几 ...

  9. WPF 几行代码实现窗体毛玻璃效果(Aero Glass)

    创建一个叫AeroGlass.cs 的类,代码如下: using System; using System.Runtime.InteropServices; using System.Windows; ...

最新文章

  1. 重新安装nginx注意事项
  2. 真,数学之美!用数学方式打开Facebook新Logo!旋转变换?
  3. 如何打开MDI文档!
  4. flutter 主题切换
  5. X-AdminABP框架开发-系统日志
  6. ubuntu配置fastdfs+Nginx
  7. Android调用默认浏览器打开指定url
  8. Xshell 6免费版
  9. python 复制图片到剪贴板_Python3把图片复制到剪贴板
  10. html5在线点餐系统源码,Web点餐系统(前端开发)
  11. When Does Self-Supervision Help Graph Convolutional Networks?
  12. 80004005错误代码_0x80004005,教您0x80004005错误代码解决方法
  13. TC气象数据下载包括NCEP的FNL(python脚本)、STI的Best_track、NOAA的SST
  14. 基于 Tensorflow 的蘑菇分类
  15. java8中的Collectors.groupingBy用法
  16. raid卡超级电容和电池的区别
  17. 分辨率720p,VGA,QVGA,WVGA
  18. centos连不上网的解决办法:
  19. pip,pip安装源
  20. 考试安全平台_ER图_功能图_数据字典_数据库脚本

热门文章

  1. ZOJ3716 Ribbon Gymnastics(贪心)
  2. Overleaf编译问题
  3. 抖音如何查看访客记录,丨国仁网络
  4. [CTF]ACSII码
  5. EtherCAT设备协议详解二、EtherCAT状态机及配置流程
  6. 音频转文字软件有哪些?推荐几个录音转文字工具
  7. MSVCR110.dll文件找不到修复
  8. Lind.DDD.Domain领域模型介绍
  9. windows shell终端推荐及对比
  10. 2022便利蜂4.14算法笔试题