问题描述
我知道这是可能的 - 在创建窗口时通过 SetWindowLong
API 或 WPF 的 Window
类的托管属性...不知道.我根本找不到有关如何设置窗口样式的信息,因此它无法接收有关鼠标单击它的任何系统消息,并且任何单击都会通过窗口到达底层窗口.
I know it is possible - somehow through SetWindowLong
API or managed property of WPF's Window
class at the moment of window's creation... but how to do that exactly I do not know. I simply cannot find the information of how to set style of a window so it could NOT receive any system messages about mouse click on it and any click would go through the window to the underlying windows.
有人知道那个样式代码之类的吗?
Does anyone know that style code or something?
推荐答案
为窗口的扩展样式设置 WS_EX_TRANSPARENT
标志.它使窗口对鼠标点击透明.
Set the WS_EX_TRANSPARENT
flag for the window's extended style. It makes the window transparent to mouse clicks.
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);
这篇关于如何在 WPF 窗口上禁用命中测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!