ShowWindowAsync 不会激活隐藏的最小化窗口?

发布于 2024-12-06 09:22:00 字数 634 浏览 0 评论 0原文

给定的外部(不属于当前进程)窗口 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生漫 2024-12-13 09:22:00

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.

铁憨憨 2024-12-13 09:22:00

这是所使用的解决方案:

ShowWindowAsync(hWnd, SW_SHOW);
// wait loop inserted here
ShowWindowAsync(hWnd, SW_RESTORE);

这本质上是用于隐藏窗口的代码片段的反转:

ShowWindowAsync(hWnd, SW_MINIMIZE);
// wait loop inserted here
ShowWindowAsync(hWnd, SW_HIDE);

Here's the solution as used:

ShowWindowAsync(hWnd, SW_SHOW);
// wait loop inserted here
ShowWindowAsync(hWnd, SW_RESTORE);

This is essentially an inversion of the snippet used to hide the window:

ShowWindowAsync(hWnd, SW_MINIMIZE);
// wait loop inserted here
ShowWindowAsync(hWnd, SW_HIDE);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文