手机
当前位置:查字典教程网 >编程开发 >C#教程 >C# 鼠标穿透窗体功能的实现方法
C# 鼠标穿透窗体功能的实现方法
摘要:同样该功能需要加载命名空间usingSystem.Runtime.InteropServices;复制代码代码如下:privateconst...

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

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);

}

【C# 鼠标穿透窗体功能的实现方法】相关文章:

解决C#全屏幕截图的实现方法

C#操作注册表的方法

C# 语音功能的实现方法

C# 透明窗体制作实现方法比较分析

C# WINFORM 强制让窗体获得焦点的方法代码

解决C# 截取当前程序窗口指定位置截图的实现方法

两路归并的数组与链表的实现方法

解决C#获取鼠标相对当前窗口坐标的实现方法

关于C#生成MongoDB中ObjectId的实现方法

C#获取进程的主窗口句柄的实现方法

精品推荐
分类导航