c# winform 局部鼠标穿透

2026年09月10日 07:56
有1个网友回答
网友(1):

[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); 
const int GWL_EXSTYLE=-20;

private void CanPenetrate(){
 uint intExTemp=GetWindowLong(this.handle,GWL_EXSTYLE);
 uint oldGWLEx=SetWindowLong(this.handle,GWL_EXSTYLE,WS_EX_TRANSPARENT|WS_EX_LAYERED);
}
private void Form1_Load(object sender,EventArgs e)
{
    this.ShowInTaskBar =false;
    CanPenetrate()
    this.TopMost=true;
}