开发者

WPF: Non focusable window

开发者 https://www.devze.com 2022-12-27 05:13 出处:网络
I am developing WPF Touch Screen Keyboard. I need to know how is it possible to make main window non focusable, so other windows will be receiving the input when I click on virtual keyboard buttons.

I am developing WPF Touch Screen Keyboard.

I need to know how is it possible to make main window non focusable, so other windows will be receiving the input when I click on virtual keyboard buttons.

Simple开发者_如何学运维 applying "Focusable="False"" to the main window and all child controls doesn't work.


I think there is a clickable attribute you can set to false which stops the form receiving click messages.


Problem was solved by using Popup instead of Window, which not grab the focus, when you click on it.


From here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/41ca3605-247c-4c5b-ac5d-74ce5abd7b92/making-a-window-invisible-to-mouse-events-ishittestvisiblefalse-not-working?forum=wpf

I've figured out how to do this. The key being the WS_EX_TRANSPARENT flag for the window's extended style.You can set the topmost property like you normally would, then this code takes care of making the window transparent to mouse clicks:

Code Snippet

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

protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);

// Get this window's handle
IntPtr hwnd = new WindowInteropHelper(this).Handle;

// Change the extended window style to include WS_EX_TRANSPARENT
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消