zoukankan      html  css  js  c++  java
  • windows 10 透明毛玻璃,winform和wpf方法

    win10的透明毛玻璃,winform和wpf方法,win7、8不能用,只是win10
     public partial class Form1 : Form
        {
            [DllImport("user32.dll")]
            internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
    
            [StructLayout(LayoutKind.Sequential)]
            internal struct WindowCompositionAttributeData
            {
                public WindowCompositionAttribute Attribute;
                public IntPtr Data;
                public int SizeOfData;
            }
    
            internal enum WindowCompositionAttribute
            {
                WCA_ACCENT_POLICY = 19
            }
    
            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;
            }
    
            internal void EnableBlur()
            {
                var accent = new AccentPolicy();
                var accentStructSize = Marshal.SizeOf(accent);
                accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
    
                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(this.Handle, ref data);
    
                Marshal.FreeHGlobal(accentPtr);
            }
    ...................
    ...................
    private void Form1_Load(object sender, EventArgs e)
            {
                EnableBlur();
            }
    
    窗体背景设置比如Red,然后TransparencyKey=Red,就有行了。
    
    如果使用WPF,修改:
    internal void EnableBlur()
    {
        var windowHelper = new WindowInteropHelper(this);
        ......
        ......
        SetWindowCompositionAttribute(windowHelper.Handle, ref data);
        ......
    }
    
  • 相关阅读:
    APPCAN   版本控制SVN
    关于 java中的换行符
    BCompare中文版安装包
    netstat
    springboot mybatis generator
    mysql删除表的方式
    jdbc写入和读取过程
    hadoop全排序和二次排序
    mapreduce之数据倾斜
    hdfs切片的计算方式
  • 原文地址:https://www.cnblogs.com/qiaoke/p/8395106.html
Copyright © 2011-2022 走看看