windows 强制窗口位于已经最顶层的窗口之上(如任务管理器)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7434638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:05:27  来源:igfitidea点击:

Force window to be above already top-most windows (like the Task Manager)

c++cwindowswinapi

提问by Steven Lu

I have a window which i would like to display above everything else. My code is able to successfully force it to be above almost every window, except for other top-most windows. Here is the code I use:

我有一个窗口,我想将其显示在其他所有内容之上。我的代码能够成功地强制它位于几乎每个窗口之上,除了其他最顶层的窗口。这是我使用的代码:

SetWindowPos(getSDLWindow(),HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);

This line is executed every time I click the middle mouse button (I am using a mouse hook to fire it).

每次单击鼠标中键时都会执行此行(我使用鼠标钩子来触发它)。

Once I start up my program, and middle-click once, from that point on, my window remains above all "regular" windows.

一旦我启动了我的程序并单击鼠标中键,从那时起,我的窗口将始终位于所有“常规”窗口之上。

However, all "special windows" seem to be in the same category as my application window, i.e. special windows when focused are displayed above my application window. In this category of special windows are the taskbar (which using the start menu also seems to activate), right-click menus (even when spawned by regular windows), the Task Manager, and I am sure many others. In fact I am fairly sure any other window which is "topmost" will behave this way. It seems that through my SetWindowPoscall I have elevated the status of my application window to a topmost window.

但是,所有“特殊窗口”似乎都与我的应用程序窗口属于同一类别,即聚焦时的特殊窗口显示在我的应用程序窗口上方。在这一类特殊窗口中,有任务栏(使用开始菜单似乎也可以激活)、右键单击菜单(即使是由常规窗口生成的)、任务管理器,我相信还有很多其他的。事实上,我相当确定“最顶层”的任何其他窗口都会以这种方式运行。似乎通过我的SetWindowPos调用,我将应用程序窗口的状态提升到了最顶层的窗口。

What's neat is that I can start the Task Manager, move it over my app window (so that it is now covering it) and then middle-click inside the Task Manager, and now my app window pops back up in front (while focus remains on the Task Manager). This is nice but I'd like to take it one step further so that my window will be on top no matter what.

巧妙的是我可以启动任务管理器,将它移动到我的应用程序窗口上(这样它现在覆盖了它)然后在任务管理器中单击鼠标中键,现在我的应用程序窗口弹出在前面(而焦点仍然存在)在任务管理器上)。这很好,但我想更进一步,这样我的窗口无论如何都会在上面。

Are there any methods to accomplish this other than repeatedly firing SetWindowPosin a loop? I'd like to avoid that if at all possible.

除了SetWindowPos在循环中重复触发之外,还有其他方法可以完成此操作吗?如果可能的话,我想避免这种情况。