如何在 WPF 窗口上禁用命中测试?

Age*_*ire 1 .net c# wpf window hittest

我知道这是可能的 -在创建窗口时通过SetWindowLongAPI 或 WPFWindow类的托管属性以某种方式......但我不知道如何做到这一点。我根本找不到有关如何设置窗口样式的信息,因此它无法接收有关鼠标单击它的任何系统消息,并且任何单击都会通过窗口到达底层窗口。

有谁知道那个样式代码之类的?

Sou*_*tra 5

设置WS_EX_TRANSPARENT窗口扩展样式的标志。它使窗口对鼠标点击透明。

public const int WS_EX_TRANSPARENT = 0x00000020;
public const int GWL_EXSTYLE = (-20);


[DllImport("user32.dll")]
public static extern int GetWindowLong(IntPtr hwnd, int index);

[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);

int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
WinAPI.SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
Run Code Online (Sandbox Code Playgroud)