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);
        ......
    }
    
  • 相关阅读:
    Java排序算法之堆排序
    servlet学习总结(一)——HttpServletRequest(转载)
    servlet学习总结(一)——初识Servlet
    Java排序算法之快速排序
    Java排序算法之直接选择排序
    第八课、泛型编程简介
    第六课、算法效率的度量
    第四课、程序灵魂的审判
    第三课、初识程序的灵魂------------------------狄泰软件学院
    用solidity语言开发代币智能合约
  • 原文地址:https://www.cnblogs.com/qiaoke/p/8395106.html
Copyright © 2011-2022 走看看