How to disable hittesting on a WPF window?

风格不统一 提交于 2019-12-11 09:19:03

问题


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?


回答1:


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);



回答2:


WS_EX_TRANSPARENT not enough.

Need WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOPMOST;

And

SetLayeredWindowAttributes(hWnd, 0, 150, LWA_ALPHA); 


来源:https://stackoverflow.com/questions/22452066/how-to-disable-hittesting-on-a-wpf-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!