简体   繁体   English

TopMost窗口有时会落后于非TopMost全屏窗口

[英]TopMost window going behind non-TopMost fullscreen window sometimes

I have a "control toolbar" app that needs to float on top of everything else on the primary screen of a dual monitor system. 我有一个“控制工具栏”应用程序,该应用程序需要浮在双显示器系统主屏幕上的所有其他内容之上。 It positions itself at the top of the primary screen and sets TopMost=true. 它将自身放置在主屏幕的顶部,并设置TopMost = true。

This control toolbar can be used to launch two other processes which run fullscreen but NOT TopMost, one on each monitor on the dual monitor system. 此控制工具栏可用于启动其他两个进程,这些进程在全屏模式下运行,但不能运行TopMost,而在双监视器系统的每个监视器上都可以启动一个进程。 These windows are setup to run fullscreen by setting BorderStyle to None and setting the bounds of the window to fit exactly into the screen dimensions. 通过将BorderStyle设置为None并将窗口的边界设置为完全适合屏幕尺寸,可以将这些窗口设置为全屏运行。 The fullscreen windows have no problem covering the taskbar, and I can focus and interact with the fullscreen window on the primary monitor all day and the toolbar stays on top. 全屏窗口不会覆盖任务栏,并且我可以全天在主监视器上聚焦全屏窗口并与之交互,工具栏始终位于顶部。

All is not peachy in the kingdom of software however - certain actions make the TopMost toolbar pop under the non-TopMost fullscreen windows. 但是,在软件王国中,一切都不尽如人意-某些操作使TopMost工具栏在非TopMost全屏窗口下弹出。 One of those actions is giving focus to the fullscreen app on the secondary monitor, then giving focus back to the fullscreen app on the primary monitor. 这些操作之一是将焦点移至辅助监视器上的全屏应用程序,然后将焦点移回到主监视器上的全屏应用程序。 This is the easiest situation to reproduce as it happens every time I follow this sequence. 每当我按照此顺序进行时,这是最容易重现的情况。 I have a hard time reproducing other scenarios reliably, but if I hit the windows key to pull up the start menu and start browsing in Internet Explorer, sometimes when I am done browsing and close IE and give focus back to the primary monitor fullscreen app it pops over the TopMost window. 我很难可靠地重现其他情况,但是如果我按Windows键以拉起开始菜单并开始在Internet Explorer中浏览, 有时在完成浏览并关闭IE并将焦点重新回到主监视器全屏应用程序时,弹出TopMost窗口。

Any idea how to keep the TopMost window on top, and not allow it to pop under a non-TopMost fullscreen window? 有什么主意如何将TopMost窗口保持在顶部,并不允许其在非TopMost全屏窗口下弹出? I wouldn't mind doing something like polling WindowFromPoint once a second to see if the toolbar is still on top and if not then pop it back over somehow, but I don't want to take focus away from the fullscreen app if that's what the user is using, so Activate() isn't a particularly good solution. 我不介意每秒进行一次轮询WindowFromPoint之类的操作,以查看工具栏是否仍在顶部,如果不是,则以某种方式将其弹出,但是如果那样的话,我不想将注意力从全屏应用程序移开用户正在使用,因此Activate()并不是一个特别好的解决方案。

I don't think this really matters, but the toolbar is a WPF window and the fullscreen apps are WinForms. 我认为这并不重要,但是工具栏是WPF窗口,全屏应用程序是WinForms。

UPDATE: 更新:

The easiest way to test this is to press F11 to go fullscreen in two browser windows on each monitor to simulate the full screen apps and then have a TopMost window floating anywhere. 最简单的测试方法是按F11键在每个监视器的两个浏览器窗口中进入全屏模式,以模拟全屏应用程序,然后在任何位置浮动一个TopMost窗口。 Click between the two fullscreen windows and you will see the TopMost window pop under them. 在两个全屏窗口之间单击,您将看到在其下弹出的TopMost窗口。 I opened IE on one monitor and Chrome on another since IE doesn't let me do two fullscreen windows. 我在一个显示器上打开了IE,在另一个显示器上打开了Chrome,因为IE不允许我做两个全屏窗口。

I implemented the Activate() hack for now, but it's a rather ugly solution because it activates the toolbar app which unfocuses the fullscreen app, which in turn makes the taskbar pop over the fullscreen app. 我现在实现了Activate()hack,但这是一个非常丑陋的解决方案,因为它激活了工具栏应用程序,使全屏应用程序失去了焦点,反过来又使任务栏弹出了全屏应用程序。 Kind of hacky when all you want to do is switch which fullscreen app has focus. 当您要做的只是切换哪个全屏应用程序具有焦点时,就有点麻烦了。

Okay, here is what I ended up doing...I came up with one more idea before I was going to give up and this works well. 好的,这就是我最终要做的事情……在我放弃之前,我又提出了一个新的主意,而且效果很好。 In the toolbar window I have a timer that polls the top most window over the toolbar area once a second, like this: 在工具栏窗口中,我有一个计时器,它每秒轮询一次工具栏区域中最上面的窗口,如下所示:

var topMostHandle = WindowFromPoint((int)(Left + ActualWidth / 2), (int)ActualHeight / 2);

if (topMostHandle != new WindowInteropHelper(this).Handle)
{
    Topmost = false;
    Topmost = true;
}

So I basically just take a point in the middle of the toolbar and test to see if the toolbar is on top. 因此,我基本上只是在工具栏的中间一点,然后测试一下工具栏是否位于顶部。 If not, I set TopMost to false and back to true, which seems to bring it back on top without activating it. 如果没有,我将TopMost设置为false,然后又设置为true,这似乎会使它回到顶部而不激活它。 The flash where it disappears for a second is slightly annoying but I don't expect this to happen often. 一秒钟消失的闪光灯有点烦人,但我不希望这种情况经常发生。

Credit to Hans Passant for finding a hotfix for Win7 SP1 that addresses the problem: http://support.microsoft.com/kb/2733420 感谢Hans Passant为Win7 SP1找到解决该问题的修补程序: http : //support.microsoft.com/kb/2733420

I kept my hack in the code in case clients can't/aren't running the hotfix as a workaround. 我将代码保存在代码中,以防客户端无法/不运行此修补程序作为解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM