How to disable hittesting on a WPF window?

2019-08-10 01:53发布

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?

2条回答
▲ chillily
2楼-- · 2019-08-10 02:39

WS_EX_TRANSPARENT not enough.

Need WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOPMOST;

And

SetLayeredWindowAttributes(hWnd, 0, 150, LWA_ALPHA); 
查看更多
霸刀☆藐视天下
3楼-- · 2019-08-10 02:45

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);
查看更多
登录 后发表回答