禁用WPF窗口焦点 [英] Disable WPF Window Focus

查看:1408
本文介绍了禁用WPF窗口焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF窗口只有当你按住通过Visibility.Hidden和Visibility.Visible Tab键,显示了。然而,按住按键后转移从活动应用程序到WPF窗口的焦点。我可以禁用这种行为?变本加厉:是有可能完全prevent从得到的焦点在单击控制甚至当,但还是注册控件的点击动作窗口

I have a WPF Window that shows up only when you hold down the tab key via Visibility.Hidden and Visibility.Visible. However, holding the key down shifts the focus from the active application to the WPF Window. Can I disable this behavior? Going even further: is it possible to completely prevent the window from getting focus even when a control is clicked, but still registering the click action of the control?

推荐答案

找到了答案其他地方:

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

        //Set the window style to noactivate.
        WindowInteropHelper helper = new WindowInteropHelper(this);
        SetWindowLong(helper.Handle, GWL_EXSTYLE,
            GetWindowLong(helper.Handle, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
    }   

    private const int GWL_EXSTYLE = -20;
    private const int WS_EX_NOACTIVATE = 0x08000000;

    [DllImport("user32.dll")]
    public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

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

这篇关于禁用WPF窗口焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆