窗口的鼠标穿透功能


(即显示文字的同时不影响下面窗口的操作) //加入WS_EX_TRANSPARENT扩展属性

ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TRANSPARENT);
//加入WS_EX_LAYERED扩展属性

ModifyStyleEx(WS_EX_APPWINDOW,GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

把窗体的FormBorderStyle设为

FormBorderStyle.None

 

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 = 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

);

/// <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, 100, LWA_ALPHA);

 

 

要时窗体恢复正常,只要执行以下语句: 

this.FormBorderStyle = FormBorderStyle.None;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM