WPF实现Aero毛玻璃效果
源码摘自 http://virtualrouter.codeplex.com
这是一个 .net的wifi工具创建笔记本共享wifi
/*
* Virtual Router v1.0 - http://virtualrouter.codeplex.com
* Wifi Hot Spot for Windows 8, 7 and 2008 R2
* Copyright (c) 2013 Chris Pietschmann (http://pietschsoft.com)
* Licensed under the Microsoft Public License (Ms-PL)
* http://virtualrouter.codeplex.com/license
*/
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;namespace VirtualRouterClient.AeroGlass
{public static class AeroGlassHelper{#region "Generic Static Methods"public static void ExtendGlass(IntPtr windowHandle){ExtendGlass(windowHandle, -1, -1, -1, -1);}public static void ExtendGlass(IntPtr windowHandle, int left, int right, int top, int bottom){internalExtendGlass(windowHandle, left, right, top, bottom);}private static int internalExtendGlass(IntPtr windowHandle, int left, int right, int top, int bottom){var retVal = -1; // Returning less than zero will indicate that Aero Glass could not be extended// Calculate the Aero Glass MarginsWin32.Margins margins = Win32.GetDpiAdjustedMargins(windowHandle, left, right, top, bottom);try{// Actually Enable Aero GlassretVal = Win32.DwmExtendFrameIntoClientArea(windowHandle, ref margins);}catch (Exception){retVal = -1;}return retVal;}#endregion#region "WPF Static Methods"public static void ExtendGlass(Window win){ExtendGlass(win, -1, -1, -1, -1);}public static void ExtendGlass(Window win, int left, int right, int top, int bottom){Brush originalBackgroundBrush = win.Background;try{int retVal = -1;if (Win32.DwmIsCompositionEnabled()){win.Background = Brushes.Transparent;// Obtain the window handle for WPF applicationWindowInteropHelper windowInterop = new WindowInteropHelper(win);IntPtr windowHandle = windowInterop.Handle;// Set the Window background to be Transparent so the Aero Glass will show throughHwndSource mainWindowSrc = HwndSource.FromHwnd(windowHandle);mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent;retVal = internalExtendGlass(windowHandle, left, right, top, bottom);}if (retVal < 0){throw new NotSupportedException("Operation Failed: Aero Glass Not Supported");}}catch{// If an error occurred then change the Window.Background back to what it waswin.Background = originalBackgroundBrush;}}#endregion//#region "Windows.Forms Static Methods"//public static void ExtendGlass(Form form)//{// ExtendGlass(form, -1, -1, -1, -1);//}//public static void ExtendGlass(Form form, int left, int right, int top, int bottom)//{// System.Drawing.Color oldBackColor = form.BackColor;// System.Drawing.Color oldTransparencyKey = form.TransparencyKey;// int retVal = -1;// try// {// form.TransparencyKey = System.Drawing.Color.Beige;// form.BackColor = form.TransparencyKey;// retVal = internalExtendGlass(form.Handle, left, right, top, bottom);// }// catch (Exception)// {// retVal = -1;// }// if (retVal < 0)// {// form.BackColor = oldBackColor;// form.TransparencyKey = oldTransparencyKey;// }//}//#endregion#region "Win32 / pinvoke"private static class Win32{[DllImport("DwmApi.dll")]public static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref Margins margins);[DllImport("dwmapi.dll", PreserveSig = false)]public static extern bool DwmIsCompositionEnabled();[StructLayout(LayoutKind.Sequential)]public struct Margins{public int Left; // width of left border that retains its sizepublic int Right; // width of right border that retains its sizepublic int Top; // height of top border that retains its sizepublic int Bottom; // height of bottom border that retains its size}public static Win32.Margins GetDpiAdjustedMargins(IntPtr windowHandle, int left, int right, int top, int bottom){float DesktopDpiX;float DesktopDpiY;// Get System Dpiusing (System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(windowHandle)){DesktopDpiX = desktop.DpiX;DesktopDpiY = desktop.DpiY;}// Set MarginsWin32.Margins margins = new Win32.Margins();// Note that the default desktop Dpi is 96dpi. The margins are// adjusted for the system Dpi.margins.Left = Convert.ToInt32(left * (DesktopDpiX / 96));margins.Right = Convert.ToInt32(right * (DesktopDpiX / 96));margins.Top = Convert.ToInt32(top * (DesktopDpiX / 96));margins.Bottom = Convert.ToInt32(bottom * (DesktopDpiX / 96));return margins;}}#endregion}
}
使用方法
在 window_Loaded 里
AeroGlassHelper.ExtendGlass(this);
//或
AeroGlassHelper.ExtendGlass(this, (int)windowContent.Margin.Left, (int)windowContent.Margin.Right, (int)windowContent.Margin.Top, (int)windowContent.Margin.Bottom);
WPF实现Aero毛玻璃效果相关推荐
- C# Winform 窗体美化(七、Win7 Aero 毛玻璃效果)
七.Win7 Aero 毛玻璃效果 在 Win7 上有一种 Aero 效果,毛玻璃透明效果,搭配不同风格的颜色,效果很好.在学习 Winform 美化的时候顺便看到的这种效果,也整理进来了. 注意:W ...
- 用C++品尝Vista美味:界面的毛玻璃效果——涨姿势
用C++品尝Vista美味:界面的毛玻璃效果_www.knowsky.com http://www.knowsky.com/395561.html 简介 本文将演示在基于Windows Vista ...
- css3 仿aero,让Qt支持Win7的Aero和毛玻璃效果
Qt5增加了许多特性,其中 Qt Windows Extras 模块就增加了对Win7 Aero 效果的支持. 官网的介绍如下: Qt Windows Extras provide classes a ...
- java swing 毛玻璃_实时、动态的毛玻璃(aero)效果,javaSwing 实现的,用的是高斯模糊算法...
[实例简介] 实时.动态的毛玻璃效果,javaSwing 实现的,ios7的毛玻璃效果可以让用户的注意力集中到他需要注意的地方,本demo根据之前写的例子改变而来,实现了实时.动态的毛玻璃效果,希望给 ...
- vscode卸载background插件_使用插件一键启用 Visual Studio Code 的毛玻璃效果
本文原文发布于我的博客 https://eyhn.in 上一次 我介绍了使用 "Custom CSS and JS Loader" 插件为 MacOS 开启毛玻璃效果.现在我把它做 ...
- C#迅雷七窗体特效,使用DWM实现Aero Glass效果
从Windows Vista开始,Aero Glass效果被应用在了Home Premium以上的系统中(Home Basic不具有该效果).这种效果是由DWM(Desktop Window Mana ...
- 【转】MFC 迅雷七窗体特效,使用DWM实现Aero Glass效果
从Windows Vista开始,Aero Glass效果被应用在了Home Premium以上的系统中(Home Basic不具有该效果).这种效果是由DWM(Desktop Window Mana ...
- css毛玻璃效果白边_CSS3毛玻璃效果(blur)有白边问题的解决方法
做一个登录页,全屏背景图毛玻璃效果,实现方法如下: HTML: var w = window.innerWidth || document.documentElement.clientWidth || ...
- 纯css实现毛玻璃效果
2019独角兽企业重金招聘Python工程师标准>>> 最近有用到毛玻璃效果,在此记录,一方面方便以后使用,另一方面也分享给其他朋友. 先上图: 通过对比,就可以看到效果还是很不错, ...
最新文章
- 最先进的开源游戏引擎KlayGE 3.12.0发布
- C++ size_t 与 size_type区别
- 有史以来最精彩的自问自答:OpenAI 转方块的机械手
- Cisco与Linux的NAT
- JavaScript对象
- iView 3.3.0 发布,基于 Vue.js 的企业级 UI 组件库
- python 错误处理 assert
- 如何给Wordpress安装插件
- C和指针之字符串之实现strcpy函数
- IXMLDOMDocument中的load方法返回值有BUG
- postgresql could not connect to server
- matlab 去除图片坐标值和白边,并用saveas函数按需要分辨率(尺寸)保存
- 作品交流:调制解调-勘误情况
- 如何制作动态图片gif
- python控制qq添加好友_QQ增粉秘籍:QQ添加好友被限制 突破规则日增粉1000+
- oracle数据库安装与打开,Oracle数据库在Linux 中的安装与启动动
- 计算机中主频的定义,计算机的主频指的
- arx开发版本对照表
- 视频号在微信生态里的定位如何?
- 一分钟了解“#include命令是干啥的”