WPF Aero Glass Window
用法
- Win7 DwmSetWindowAttribute function
- Win10 SetWindowCompositionAttribute
- 代码
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>
- 效果

WPF Aero Glass Window的更多相关文章
- Windows 7 扩展玻璃效果(Aero Glass)
转自:http://www.cnblogs.com/gnielee/archive/2010/10/04/windows7-extend-aero-glass.html Windows 7 操作系统默 ...
- 【转】MFC 迅雷七窗体特效,使用DWM实现Aero Glass效果
从Windows Vista开始,Aero Glass效果被应用在了Home Premium以上的系统中(Home Basic不具有该效果).这种效果是由DWM(Desktop Window Mana ...
- 窗口玻璃特效,半透明窗口,使用DWM实现Aero Glass效果
转自:http://blog.csdn.net/ntwilford/article/details/5656633 从Windows Vista开始,Aero Glass效果被应用在了Home Pre ...
- C# WPF 多个window 相互覆盖的次序控制 不用topmost
原文:C# WPF 多个window 相互覆盖的次序控制 不用topmost WindowInteropHelper mianHanel = new WindowInteropHelper(Mai ...
- WPF 不要给 Window 类设置变换矩阵(分析篇):System.InvalidOperationException: 转换不可逆。
原文:WPF 不要给 Window 类设置变换矩阵(分析篇):System.InvalidOperationException: 转换不可逆. 最近总是收到一个异常 "System.Inva ...
- WPF 不要给 Window 类设置变换矩阵(应用篇)
原文:WPF 不要给 Window 类设置变换矩阵(应用篇) WPF 的 Window 类是不允许设置变换矩阵的.不过,总会有小伙伴为了能够设置一下试图绕过一些验证机制. 不要试图绕过,因为你会遇到更 ...
- WPF直接用Window.Close直接关闭窗口导致不能完全退出的问题
前几天我在CSDN扔了一个问题,基本描述一下:写了一段这样的代码,来实现获取Control的template,却发现一个这样的问题,就是当我打开了一个window以后,手动调用Close(),窗口的确 ...
- WPF 中保存 window(窗口)或者canvas成图片
最近需要用到这个功能,搜了一下不少代码有问题 ,找到一个效果比较好的,支持多级子元素 记一下. private void button_save_window_Click(object sender, ...
- wpf 只在window是ShowDialog打开时才设置DialogResult
//only set DialogResult when window is ShowDialog before if(System.Windows.Interop.ComponentDispatch ...
随机推荐
- c头文件(.h)的作用
C语言的著作中,至今还没发现把.h文件的用法写的透彻的.在实际应用中也只能依葫芦画瓢,只知其然不知其所以然,甚是郁闷!闲来无事,便将搜集网络的相关内容整理一下,以便加深自己的理解 理论概述:.h中一般 ...
- 三步学会用spring开发OSGI——(第一步:环境篇)
Spring-DM是什么 Spring-DM 指的是Spring Dynamic Modules. dm Server 是一个完全模块化部署的,基于OSGi的Java服务器,为运行企业Java应用和S ...
- 数据挖掘之分类算法---knn算法(有matlab样例)
knn算法(k-Nearest Neighbor algorithm).是一种经典的分类算法. 注意,不是聚类算法.所以这样的分类算法必定包含了训练过程. 然而和一般性的分类算法不同,knn算法是一种 ...
- js进阶 9-7 自动计算商品价值
js进阶 9-7 自动计算商品价值 一.总结 一句话总结: 1.form表单控件value属性:属性可取值可赋值 2.文本onchange事件 3.form及form中控件通过name访问元素 二. ...
- sparksql load/save
java public class LoadAndSaveDemo { private static SparkConf conf = new SparkConf().setAppName(" ...
- MSYS是一个小型的GNU环境,包括基本的bash,make等等,与Cygwin大致相当(双击“D:\MinGW\msys\1.0\msys.bat”,启动MinGW终端)
1 简介 MinGW,是Minimalist GNUfor Windows的缩写.它是一个可自由使用和自由发布的Windows特定头文件和使用GNU工具集导入库的集合,允许你在GNU/Linux和 ...
- Linux 在主要的搜索命令和视图的信息
查找命令和硬件信息查看的日常系统管理.最常见的维护操作. 继 Linux 基本查找命令做一个简单的比较.并列出了一些硬件信息经常使用的视图命令. man 经常使用选项 -k 知道功能.不知道名称 -f ...
- AndroidStudio封装SDK的那些事
来自自己简书博客:原文地址:https://www.jianshu.com/p/4d092c915ef1 首先SDK是提供给别人调用的工具.所以常见的SDK都是以jar包,so库,aar包等方式导入A ...
- [Android]TextView点击获取部分内容
TextView控件本身有很多属性可以进行控制,如果要获取内容只需要getText()方法就可以实现,同时也可以为TextView设置各种监听器.但是,如果想要实现点击获取TextView内部的部分内 ...
- Delphi2010,DelphiXE 安装控件找不到DesignIntf 解决办法
今天安装了一个可以支持IP 地址输入的edit控件,安装后可以放到窗体上,但是编译提示找不到DesignIntf,DesignEditors 从Delphi6开始,就对DesignIntf,Desig ...