如何在不激活其他应用程序窗口的情况下将其置于前面?

发布于 2024-10-20 23:08:12 字数 362 浏览 4 评论 0原文

我想将一个窗口带到前面(来自其他应用程序)。目前我正在使用:

::SetWindowPos(hwnd, GetForegroundWindow(), 0, 0, 0, 0, SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);

它工作正常,但在某些(我不知道的)情况下,它使窗口始终位于顶部。根据 MSDN,我应该使用 HWND_NOTOPMOST 代替 GetForegroundWindow(),但它不起作用 - 窗口保留在其他窗口下方(并不总是在顶部)。

如何在不激活窗口的情况下将其置于前面?

I want to bring to front a window(from other application). Currently I'm using:

::SetWindowPos(hwnd, GetForegroundWindow(), 0, 0, 0, 0, SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);

It works fine, but in some (unknown to me) cases, it makes the window always on top. According to MSDN, I should use HWND_NOTOPMOST in the place of GetForegroundWindow() but it doesn't work—the window stays under other (not always on top) windows.

How can I bring a window to the front without activating it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

自由如风 2024-10-27 23:08:12

可以将其他应用程序的窗口临时设置为“最顶层”,以将其置于最前面而不激活它,首先在 SetWindowPos 调用中将 HWND_TOPMOST 指定为“hWndInsertAfter”,然后通过在第二次调用中指定 HWND_NOTOPMOST(两次调用都在“uFlags”中使用 SWP_NOACTIVATE)。如果由于操作而存在删除已经位于最顶层的窗口的最顶层样式的风险,则可以通过调用 预先测试 WS_EX_TOPMOST ex-style GetWindowLong[Ptr]

如果存在另一个应用程序的窗口需要位于前面的特定窗口(而不是位于所有窗口的前面),则可以再次临时将该窗口的所有者设置为它需要位于前面的窗口。 GetWindowLong[Ptr]GWL_HWNDPARENT 可用于存储窗口的原始所有者,然后调用 SetWindowLong[Ptr] 来设置临时所有者,然后使用 HWND_TOP 调用 SetWindowPos,然后再次使用 SetWindowLong[Ptr] 恢复原始所有者。

The other application's window can be made temporarily 'top-most' to bring it to front without activating it, first by specifying HWND_TOPMOST as 'hWndInsertAfter' in a SetWindowPos call and then by specifying HWND_NOTOPMOST in a second call (both calls with SWP_NOACTIVATE in 'uFlags'). If there's a risk of removing the top-most style of a window which is already top-most as a consequence of the operation, the WS_EX_TOPMOST ex-style can be tested beforehand with a call to GetWindowLong[Ptr].

If there's a particular window that the other application's window need to be in front (as opposed to being in front of all windows), that window's owner can be set, again temporarily, to the window it needs to be in front. GetWindowLong[Ptr] with GWL_HWNDPARENT can be used to store the window's original owner, then a call to SetWindowLong[Ptr] to set the temporary owner, followed by a call to SetWindowPos with HWND_TOP, and then restoring the original owner with again SetWindowLong[Ptr].

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