在什么条件下,允许使用Win32函数SetForegroundWindow设置前景窗口?
我想了解一个过程可以使用win32函数 setForegroundWindow
。我尝试阅读其文档,并在下说:
一个过程只有在以下条件之一为真时才能设置前景窗口:
- 该过程是前景过程。
- 该过程是由前景过程开始的。
- 该过程收到了最后一个输入事件。
- 没有前景过程。
- 该过程正在调试。
- 前景过程不是现代应用程序或开始屏幕。
- 前景未锁定(请参阅
lockset Foregroundwindow
)。- 前景锁定超时已过期(请参阅
spi_get foregroundlocktimeout
insystemparametersinfo
)。- 没有菜单活跃。
在我看来,这是不准确的,因为这意味着所有这些子弹都必须是错误的才能限制设置前景窗口,但是最后四个似乎通常是正确的(取决于您使用“现代”应用程序)。因此,正如书面的那样,设置前景窗口几乎永远不会受到限制。在实验上,似乎在另一个过程中拥有一个活动菜单“足以阻止设置前景窗口,即使前景过程不是现代应用程序(条件6是正确的)。
什么时候可以根据列出的条件设置前景窗口时表达更准确的方法?
I want to understand under what conditions a process can set the foreground window using the Win32 function SetForegroundWindow
. I tried reading its documentation and it says under Remarks:
A process can set the foreground window only if one of the following conditions is true:
- The process is the foreground process.
- The process was started by the foreground process.
- The process received the last input event.
- There is no foreground process.
- The process is being debugged.
- The foreground process is not a Modern Application or the Start Screen.
- The foreground is not locked (see
LockSetForegroundWindow
).- The foreground lock time-out has expired (see
SPI_GETFOREGROUNDLOCKTIMEOUT
inSystemParametersInfo
).- No menus are active.
It seems to me that this cannot be accurate, as it would mean that all of these bullets would have to be false to restrict setting the foreground window, but the last four seem to be normally true (depending on your use of "modern" applications). So as written, setting the foreground window would almost never be restricted. Whereas experimentally it seems that having a menu active in another process' window is sufficient to block setting the foreground window, even if e.g. the foreground process is not a Modern Application (condition 6 is true).
What would be a more accurate way to express when a process can set the foreground window based on the listed conditions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MSDN文档已经迁移了很多次到不同的格式。每次微软这样做时,文档都会遭受损失。
文章更正确:
请特别注意最后一句话。因此,最好不要太努力地考虑它,因为它可能无缘无故地失败。
MSDN docs have been migrated a lot of times to different formats. Every time Microsoft did that, the documentation has suffered.
The Window Features article is more correct:
Please especially note the last sentence. So, better not think about it too hard, because it may fail anyway for no reason.