简体   繁体   English

如何将Windows应用程序设置为始终位于其他窗口之下?

[英]How do I set a Windows application to be always below other windows?

I would like to be able to set any window (for example Google Chrome) to be always below all other windows and prevent it to come to the top when activated. 我希望能够将任何窗口(例如Google Chrome)设置为始终位于所有其他窗口下方,并防止其在激活时出现在顶部。 I found this on stackoverflow. 我在stackoverflow上发现了这个 What I am looking for is nearly the same, but for compiled applications. 我正在寻找的几乎是相同的,但对于已编译的应用程序。 Using Ubuntu I could achieve this using wmctrl -i -r <window_handle> -b add,below but I found no corresponding possibility under Windows (in my case Windows 7 x64). 使用Ubuntu,我可以wmctrl -i -r <window_handle> -b add,below使用wmctrl -i -r <window_handle> -b add,below来实现这一点wmctrl -i -r <window_handle> -b add,below但是在Windows(在我的情况下为Windows 7 x64)下wmctrl -i -r <window_handle> -b add,below我找不到相应的可能性。

I could not find such a command line function but you could still do it from a compiled program. 我找不到这样的命令行功能,但是您仍然可以从编译的程序中执行。

First find Google Chrome's window handle: Source 首先找到Google Chrome的窗口句柄: 来源

The only way I know of is to enumerate all the top level windows with EnumWindows() and then find what process each belongs to GetWindowThreadProcessID(). 我知道的唯一方法是使用EnumWindows()枚举所有顶级窗口,然后找到每个属于GetWindowThreadProcessID()的进程。 This sounds indirect and inefficient, but it's not as bad as you might expect -- in a typical case, you might have a dozen top level windows to walk through... 这听起来是间接的且效率低下的,但并不像您预期​​的那样糟糕-在典型情况下,您可能要通过十几个顶层窗口来浏览...

Then use SetWindowPos with the flag HWND_BOTTOM for that HWND. 然后将SetWindowPos与HWND_BOTTOM标志一起使用。 The user might try to bring Chrome to the foreground which you could prevent by checking GetForegroundWindow and if necessary call SetWindowPos again. 用户可能会尝试通过检查GetForegroundWindow来阻止Chrome进入前台,并在必要时再次调用SetWindowPos。

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

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