資源簡介
自適應(yīng)操作系統(tǒng),可在Win7系統(tǒng)下使用系統(tǒng)毛玻璃,在Win10下使用毛玻璃濾鏡,其他系統(tǒng)下使用透明窗口,其中Win7下受系統(tǒng)的主題及顏色影響,毛玻璃的可定制性差,而在Win10下,毛玻璃顏色及透明度均可以自定義,不受系統(tǒng)的任何設(shè)置影響,即使系統(tǒng)設(shè)定為高對比度原始主題,程序仍舊能顯示毛玻璃效果,程序只是借用了系統(tǒng)的高斯濾鏡而已,Win8系統(tǒng)下未測試,不知有無Win10的特效。

代碼片段和文件信息
using?System;
using?System.Windows;
using?System.Windows.Controls;
using?System.Windows.Data;
using?System.Windows.Documents;
using?System.Windows.Input;
using?Standard;
using?GenLibrary.MVVM.base;
using?System.ComponentModel;
using?System.Windows.Interop;
using?System.Runtime.InteropServices;
using?System.Windows.Media;
namespace?GenLibrary.GenWindows
{
????///?
????///?Window1.xaml?的交互邏輯
????///?
????[TemplatePart(Name?=?“PART_borderframe“?Type?=?typeof(Border))]
????public?class?GlassWindow?:?Window
????{
????????static?bool?IsWin7?=?false;
????????static?bool?IsWin10?=?false;
????????#region?使用系統(tǒng)毛玻璃Win10下可用
????????internal?enum?AccentState
????????{
????????????ACCENT_DISABLED?=?0
????????????ACCENT_ENABLE_GRADIENT?=?1
????????????ACCENT_ENABLE_TRANSPARENTGRADIENT?=?2
????????????ACCENT_ENABLE_BLURBEHIND?=?3
????????????ACCENT_INVALID_STATE?=?4
????????}
????????[StructLayout(LayoutKind.Sequential)]
????????internal?struct?AccentPolicy
????????{
????????????public?AccentState?AccentState;
????????????public?int?AccentFlags;
????????????public?int?GradientColor;
????????????public?int?AnimationId;
????????}
????????[StructLayout(LayoutKind.Sequential)]
????????internal?struct?WindowCompositionAttributeData
????????{
????????????public?WindowCompositionAttribute?Attribute;
????????????public?IntPtr?Data;
????????????public?int?SizeOfData;
????????}
????????internal?enum?WindowCompositionAttribute
????????{
????????????//?...
????????????WCA_ACCENT_POLICY?=?19
????????????//?...
????????}
????????[DllImport(“user32.dll“)]
????????internal?static?extern?int?SetWindowCompositionAttribute(IntPtr?hwnd?ref?WindowCompositionAttributeData?data);
????????internal?void?EnableBlur()
????????{
????????????var?windowHelper?=?new?WindowInteropHelper(this);
????????????var?accent?=?new?AccentPolicy();
????????????accent.AccentState?=?AccentState.ACCENT_ENABLE_BLURBEHIND;
????????????var?accentStructSize?=?Marshal.SizeOf(accent);
????????????var?accentPtr?=?Marshal.AllocHGlobal(accentStructSize);
????????????Marshal.StructureToPtr(accent?accentPtr?false);
????????????var?data?=?new?WindowCompositionAttributeData();
????????????data.Attribute?=?WindowCompositionAttribute.WCA_ACCENT_POLICY;
????????????data.SizeOfData?=?accentStructSize;
????????????data.Data?=?accentPtr;
????????????SetWindowCompositionAttribute(windowHelper.Handle?ref?data);
????????????Marshal.FreeHGlobal(accentPtr);
????????}
????????#endregion
????????#region?使用系統(tǒng)毛玻璃Win7下可用
????????[DllImport(“DwmApi.dll“)]
????????static?extern?int?DwmExtendframeIntoClientArea(IntPtr?hwnd?ref?MARGINS?pMarInset);
????????[DllImport(“dwmapi.dll“?PreserveSig?=?false)]
????????static?extern?bool?DwmIsCompositionEnabled();
????????#endregion
????????#region?窗體初始化
????????static?GlassWindow()
????????{
????????????//啟用自定義窗口風(fēng)格
????????????DefaultstyleKeyProperty.Overridemetadata(typeof(Gl
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.????104960??2016-06-11?11:02??WpfGlassWindow\.vs\WpfGlassWindow\v14\.suo
?????文件?????154112??2016-06-11?11:00??WpfGlassWindow\GenLibrary\bin\Debug\GenLibrary.dll
?????文件?????212480??2016-06-11?11:00??WpfGlassWindow\GenLibrary\bin\Debug\GenLibrary.pdb
?????文件??????15866??2016-06-11?11:00??WpfGlassWindow\GenLibrary\Extended\GenWindows\GlassWindow.cs
?????文件????????797??2016-06-11?09:05??WpfGlassWindow\GenLibrary\Extended\GenWindows\Themes\ColorBrush.xaml
?????文件??????22822??2016-06-11?10:36??WpfGlassWindow\GenLibrary\Extended\GenWindows\Themes\Generic.xaml
?????文件???????2668??2016-06-11?10:30??WpfGlassWindow\GenLibrary\Extended\MVVM\Relaycommand.cs
?????文件???????9309??2016-06-02?14:22??WpfGlassWindow\GenLibrary\Extended\WindowClass\ComGuids.cs
?????文件??????14727??2016-06-11?10:27??WpfGlassWindow\GenLibrary\Extended\WindowClass\Debug.cs
?????文件???????6979??2016-06-02?14:22??WpfGlassWindow\GenLibrary\Extended\WindowClass\DoubleUtil.cs
?????文件???????4473??2016-06-11?10:32??WpfGlassWindow\GenLibrary\Extended\WindowClass\DpiHelper.cs
?????文件??????33479??2016-06-11?10:27??WpfGlassWindow\GenLibrary\Extended\WindowClass\ErrorCodes.cs
?????文件???????1863??2016-06-11?10:34??WpfGlassWindow\GenLibrary\Extended\WindowClass\Helper\DpiHelper.cs
?????文件???????5725??2016-06-02?14:22??WpfGlassWindow\GenLibrary\Extended\WindowClass\MessageWindow.cs
?????文件?????146438??2016-06-11?10:27??WpfGlassWindow\GenLibrary\Extended\WindowClass\NativeMethods.cs
?????文件??????49821??2016-06-02?14:22??WpfGlassWindow\GenLibrary\Extended\WindowClass\ShellProvider.cs
?????文件??????23710??2016-06-02?14:22??WpfGlassWindow\GenLibrary\Extended\WindowClass\StreamHelper.cs
?????文件??????28262??2016-06-02?14:22??WpfGlassWindow\GenLibrary\Extended\WindowClass\Utilities.cs
?????文件???????3624??2016-06-02?14:22??WpfGlassWindow\GenLibrary\Extended\WindowClass\Utilities.Windows.cs
?????文件??????15667??2016-06-02?14:22??WpfGlassWindow\GenLibrary\Extended\WindowClass\Utilities.Wpf.cs
?????文件??????13944??2016-06-02?14:22??WpfGlassWindow\GenLibrary\Extended\WindowClass\Verify.cs
?????文件??????23308??2016-06-11?10:34??WpfGlassWindow\GenLibrary\Extended\WindowClass\WindowResizer.cs
?????文件???????4163??2016-06-11?10:38??WpfGlassWindow\GenLibrary\GenLibrary.csproj
?????文件???????7210??2016-06-11?10:38??WpfGlassWindow\GenLibrary\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????910??2016-06-11?10:38??WpfGlassWindow\GenLibrary\obj\Debug\Extended\GenWindows\Themes\ColorBrush.baml
?????文件??????12615??2016-06-11?11:00??WpfGlassWindow\GenLibrary\obj\Debug\Extended\GenWindows\Themes\Generic.baml
?????文件???????3015??2016-06-11?11:00??WpfGlassWindow\GenLibrary\obj\Debug\GeneratedInternalTypeHelper.g.cs
?????文件???????3015??2016-06-11?11:00??WpfGlassWindow\GenLibrary\obj\Debug\GeneratedInternalTypeHelper.g.i.cs
?????文件???????1281??2016-06-11?10:38??WpfGlassWindow\GenLibrary\obj\Debug\GenLibrary.csproj.FileListAbsolute.txt
?????文件?????154112??2016-06-11?11:00??WpfGlassWindow\GenLibrary\obj\Debug\GenLibrary.dll
............此處省略92個文件信息
評論
共有 條評論