• 大小: 495KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-05-24
  • 语言: C#
  • 标签: WPF  毛玻璃  Glass  

资源简介

自适应操作系统,可在Win7系统下使用系统毛玻璃,在Win10下使用毛玻璃滤镜,其他系统下使用透明窗口,其中Win7下受系统的主题及颜色影响,毛玻璃的可定制性差,而在Win10下,毛玻璃颜色及透明度均可以自定义,不受系统的任何设置影响,即使系统设定为高对比度原始主题,程序仍旧能显示毛玻璃效果,程序只是借用了系统的高斯滤镜而已,Win8系统下未测试,不知有无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 使用系统毛玻璃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 使用系统毛玻璃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()
        {
            //启用自定义窗口风格
            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个文件信息

评论

共有 条评论