10年11个月前IP:北京
803259
18楼
窝也来一发
窝的这个支持win7的aero 也支持win10的blur 还有一些系统菜单 拖动之类的功能

这个保存为一个类文件即可调用
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
  
namespace Aero
{
    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
        // ...
    }
  
    class Win10Style
    {
        [DllImport("dwmapi.dll")]
        public static extern void DwmIsCompositionEnabled(ref int enabledptr);
        [DllImport("dwmapi.dll")]
        public static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margin);
  
  
  
        [DllImport("User32.dll")]
        public static extern IntPtr GetSystemMenu(IntPtr hWnd, [MarshalAs(UnmanagedType.Bool)]bool bRevert);
  
  
  
        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern long TrackPopupMenuEx(IntPtr hMenu, uint un, uint n1, uint n2, IntPtr hWnd, IntPtr lpTPMParams);
        [DllImport("user32.dll", EntryPoint = "PostMessage", CallingConvention = CallingConvention.Winapi)]
        public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam);
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        [DllImport("user32.dll")]
        public static extern long GetCursorPos(ref Point lpPoint);
  
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;
  
  
  
  
  
  
        [DllImport("user32.dll")]
        public static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
  
  
        public struct MARGINS
        {
            public int m_Left;
            public int m_Right;
            public int m_Top;
            public int m_Buttom;
        };
  
        //Win10专用
        public static void EnableBlur(IntPtr HWnd)
        {
  
            var accent = new AccentPolicy();
            accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
            accent.GradientColor = 0xFF0000;
  
            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(HWnd, ref data);
  
            Marshal.FreeHGlobal(accentPtr);
        }
  
        //Vista之后通用
        public static void EnableAero(Form target)
        {
            MARGINS mg = new MARGINS();
            mg.m_Buttom = -1;
            mg.m_Left = -1;
            mg.m_Right = -1;
            mg.m_Top = -1;
  
            DwmExtendFrameIntoClientArea(target.Handle, ref mg);
            Color aeroColor = Color.FromArgb(164, 212, 211);
            target.BackColor = aeroColor;
            target.TransparencyKey = aeroColor;
        }
  
        public static void DragWindow(IntPtr hwnd)
        {
            ReleaseCapture();
            SendMessage(hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
        }
  
        public static void ShowSystemMenu(IntPtr hwnd)
        {
            const uint TPM_RETURNCMD = 0x0100;
            const uint TPM_LEFTBUTTON = 0x0;
  
            if (hwnd == IntPtr.Zero)
            {
                return;
            }
  
            Point defPnt = new Point();
            GetCursorPos(ref defPnt);
  
            IntPtr hmenu = GetSystemMenu(hwnd, false);
  
            long cmd = TrackPopupMenuEx(hmenu, TPM_LEFTBUTTON | TPM_RETURNCMD,
                (uint)defPnt.X, (uint)defPnt.Y,
                hwnd, IntPtr.Zero);
            if (0 != cmd)
            {
                PostMessage(hwnd, WM_SYSCOMMAND, new IntPtr(cmd), IntPtr.Zero);
            }
        }
    }
}



调用示范:
private void Form1_Load(object sender, EventArgs e)
{
    Aero.Win10Style.EnableBlur(this.Handle);
    Aero.Win10Style.EnableAero(this);
}
 
private void panelExtended_MouseDown(object sender, MouseEventArgs e)
{
    Aero.Win10Style.DragWindow(this.Handle);
}
 
private void panelExtended_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
        Aero.Win10Style.ShowSystemMenu(this.Handle);
}
评论
文号 / 803259

万流景仰
名片发私信
学术分 11
总主题 171 帖总回复 1713 楼拥有证书:学者 机友 笔友
注册于 2011/09/23 14:21:19最后登录 2026/04/15 00:20:51
主体类型:个人
所属领域:无
认证方式:手机号
IP归属地:0

个人简介

怪哉!灵异的三极管电流流向! 这素一个在仿真的RCC电路,示波器上绿色的是集电极电流红色的是发射极电流。窝萌都知道发射姬电流素集电极电流和基极电流之和,所以讲道理发射极电流一定比集电极略大。可仿真结果刷了三观,Q1集电极电流一部分流经基极,然后流经Q2的C->E。

笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的