ShowWindowAsync 不会激活隐藏的最小化窗口?
给定的外部(不属于当前进程)窗口 (hWnd
) 首先最小化,然后隐藏:
ShowWindowAsync(hWnd, SW_MINIMIZE);
// wait loop inserted here
ShowWindowAsync(hWnd, SW_HIDE);
以下调用正确地将其恢复到未最小化(恢复)状态:
ShowWindow(hWnd, SW_RESTORE);
但是,此调用确实不:
ShowWindowAsync(hWnd, SW_RESTORE);
在使用 ShowWindowAsync()
的第二个实例中,窗口未最小化且不再隐藏,但未激活(保留在其他现有窗口后面)。相反,第一个 ShowWindow()
调用会正确激活窗口。
这是预期的行为吗? 如何在不依赖同步(阻塞)的 ShowWindow()
的情况下恢复窗口(到前台)?(示例中的等待循环可以有超时) ,而 ShowWindow()
不允许指定超时。)
(WinXP SP3)
A given external (not owned by the current process) window (hWnd
) is first minimized, then hidden:
ShowWindowAsync(hWnd, SW_MINIMIZE);
// wait loop inserted here
ShowWindowAsync(hWnd, SW_HIDE);
The following call properly restores it to the un-minimized (restored) state:
ShowWindow(hWnd, SW_RESTORE);
However, this call does not:
ShowWindowAsync(hWnd, SW_RESTORE);
In the second instance with ShowWindowAsync()
, the window is un-minimized and no longer hidden, but it is not activated (remains behind other existing windows). Conversely, the first ShowWindow()
call correctly activates the window.
Is this expected behavior? How can I restore the window (to the foreground) without relying on ShowWindow()
, which is synchronous (blocking)? (The wait loop in the example can have a timeout, while ShowWindow()
does not allow specification of a timeout.)
(WinXP SP3)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ShowWindowAsync 将显示窗口事件发布到给定窗口的消息队列。特别是,窗口是由它的线程而不是您的线程显示的。不同之处在于,您的线程是前台线程,因此可以激活另一个窗口,但它本身无法执行此操作。
ShowWindowAsync posts a show-window event to the message queue of the given window. In particular, the window is shown by its thread, rather than your thread. And the difference is that your thread is the foreground thread, and can therefore activate another window, which it can't do itself.
这是所使用的解决方案:
这本质上是用于隐藏窗口的代码片段的反转:
Here's the solution as used:
This is essentially an inversion of the snippet used to hide the window: