亲宝软件园·资讯

展开

C# 鼠标穿透窗体功能 C# 鼠标穿透窗体功能的实现方法

人气:0
想了解C# 鼠标穿透窗体功能的实现方法的相关内容吗,在本文为您仔细讲解C# 鼠标穿透窗体功能的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:C#,鼠标穿透窗体,下面大家一起来学习吧。

同样该功能需要加载命名空间

using System.Runtime.InteropServices;

复制代码 代码如下:

private const uint WS_EX_LAYERED = 0x80000;
        private const int WS_EX_TRANSPARENT = 0x20;
        private const int GWL_STYLE = (-16);
        private const int GWL_EXSTYLE = (-20);
        private const int LWA_ALPHA = 0;

        [DllImport("user32", EntryPoint = "SetWindowLong")]
        private static extern uint SetWindowLong(
        IntPtr hwnd,
        int nIndex,
        uint dwNewLong
        );

        [DllImport("user32", EntryPoint = "GetWindowLong")]
        private static extern uint GetWindowLong(
        IntPtr hwnd,
        int nIndex
        );

        [DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
        private static extern int SetLayeredWindowAttributes(
        IntPtr hwnd,
        int crKey,
        int bAlpha,
        int dwFlags
        );

        /// <summary>
        /// 设置窗体具有鼠标穿透效果
        /// </summary>
        public void SetPenetrate()
        {
            GetWindowLong(this.Handle, GWL_EXSTYLE);
            SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
            SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA);
        }

加载全部内容

相关教程
猜你喜欢
用户评论