c# 鼠标穿透窗体 张宇轩
2010-08-31 09:01
302 查看
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 = 0x2;
[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
);
private void MaskForm_Load(object sender, EventArgs e)
{
//要时窗体恢复正常,只要执行以下语句:
// this.FormBorderStyle = FormBorderStyle.None;
CanPenetrate();
}
/// <summary>
/// 使窗口有鼠标穿透功能
/// </summary>
public void CanPenetrate()
{
uint intExTemp = GetWindowLong(this.Handle, GWL_EXSTYLE);
uint oldGWLEx = SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
SetLayeredWindowAttributes(this.Handle, 0, 200, LWA_ALPHA);
}
private const int WS_EX_TRANSPARENT = 0x20;
private const int GWL_STYLE = (-16);
private const int GWL_EXSTYLE = (-20);
private const int LWA_ALPHA = 0x2;
[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
);
private void MaskForm_Load(object sender, EventArgs e)
{
//要时窗体恢复正常,只要执行以下语句:
// this.FormBorderStyle = FormBorderStyle.None;
CanPenetrate();
}
/// <summary>
/// 使窗口有鼠标穿透功能
/// </summary>
public void CanPenetrate()
{
uint intExTemp = GetWindowLong(this.Handle, GWL_EXSTYLE);
uint oldGWLEx = SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
SetLayeredWindowAttributes(this.Handle, 0, 200, LWA_ALPHA);
}
相关文章推荐
- C# 鼠标穿透窗体与恢复
- C#窗体设计------鼠标穿透窗体
- C# Winform 窗体美化(五、鼠标穿透)
- C# 鼠标穿透窗体功能
- C#制作鼠标可以穿透的窗体
- 用C#写依附于桌面的透明带鼠标穿透窗体的总结。
- C#制作鼠标可以穿透的窗体
- C# 鼠标穿透窗体功能的实现方法
- C#窗体dataGridView控件鼠标双击显示信息
- c# 给窗体添加MouseEnter事件,可鼠标移到任意控件均会产生MouseEnter事件,如何识别是哪个产生的呢?
- C# winform 无边框窗体鼠标点击移动事件
- C#WinForm无边框窗体移动方法、模仿鼠标单击标题栏移动窗体位置
- c#实现随鼠标移动窗体
- C# 鼠标穿透功能
- C#在窗体中点击任意位置鼠标左键获得该点坐标
- C#使用Windows API实现桌面上的遮罩层(鼠标穿透)
- C#鼠标按住标题移动时移动窗体
- c# 固定窗体位置 即窗体不能被鼠标移动
- c# 鼠标点击控件即拖动窗体
- C#基础系列:开发自己的窗体设计器(在容器上拖动鼠标增加控件)