如何让最上面的窗口保持在最上面?

发布于 2024-09-05 18:49:01 字数 1044 浏览 4 评论 0原文

我将首先解释为什么我需要它,因为我预计第一反应将是“为什么你需要它?”。我想检测鼠标光标何时位于屏幕边缘,但我不想使用挂钩。因此,我创建了一个像素宽的 TOPMOST 隐形窗口。

我在 Win XP 上使用 C++,因此当创建窗口时 (CreateWindowEx(WS_EX_TOPMOST | WS_EX_TRANSPARENT ...) 一切正常。

不幸的是,如果用户移动另一个最上面的窗口,例如我的窗口上的任务栏,我不会 :

我试图用类似于以下建议的方法来解决这个问题 如何使 MDI 窗口始终位于顶部

我尝试检查最顶层窗口的 Z 顺序在 WM_WINDOWPOSCHANGED 首先,

case WM_WINDOWPOSCHANGED :
    WINDOWPOS* pWP = (WINDOWPOS*)lParam;

pWP->hwnd 指向我的窗口,pWP->hwndInsertAfter 为 0,这应该意味着我的窗口位于 Z 的顶部,即使它被任务栏覆盖。然后我尝试:

case WM_WINDOWPOSCHANGED :
    HWND topWndHndl = GetNextWindow(myHandle, GW_HWNDPREV)
    GetWindowText(topWndHndl, pszMem, cTxtLen + 1);

并且我总是会发现“默认 IME”窗口位于我的窗口顶部。即使尝试使用 SetWindowPos() 或 BringWindowToTop () 将窗口置于顶部,“默认 IME”仍保留在顶部。我不知道什么是“默认 IME”以及如何检测任务栏是否位于窗口顶部。

所以我的问题是:如何检测我的最顶层窗口不再是最顶层窗口以及如何将其保持在顶部?

PS 我知道定期将窗口置于顶部的“强力”方法是有效的,但很丑陋,并且可能会对通知窗口产生一些不必要的推断。 (将我的窗口置于顶部将隐藏通知窗口。)

感谢您的时间和建议!

I will first explain why I need it, because I anticipate that the first response will be "Why do you need it?". I want to detect when the mouse cursor is on an edge of the screen and I don't want to use hooks. Hence, I created one pixel wide TOPMOST invisible window.

I am using C++ on Win XP, so when the window is created (CreateWindowEx(WS_EX_TOPMOST | WS_EX_TRANSPARENT ...) everything works fine.

Unfortunately, if a user moves another topmost window, for example the taskbar over my window, I don't get mouse movements.

I tried to solve this similarly to approaches suggested in:
How To Keep an MDI Window Always on Top

I tried to check for Z-order of my topmost window in WM_WINDOWPOSCHANGED first with

case WM_WINDOWPOSCHANGED :
    WINDOWPOS* pWP = (WINDOWPOS*)lParam;

yet pWP->hwnd points to my window and pWP->hwndInsertAfter is 0, which should mean that my window is on the top of the Z, even though it is covered with the taskbar. Then I tried:

case WM_WINDOWPOSCHANGED :
    HWND topWndHndl = GetNextWindow(myHandle, GW_HWNDPREV)
    GetWindowText(topWndHndl, pszMem, cTxtLen + 1);

and I'll always get that the "Default IME" window is on top of my window. Even if try to bring my window to the top with SetWindowPos() or BringWindowToTop (), "Default IME" stays on the top. I don't know what is "Default IME" and how to detect if the taskbar is on top of my window.

So my question is: How to detect that my topmost window is not the top topmost window anymore and how to keep it on the top?

P.S. I know that a "brute force" approach of periodically bringing my window to the top works, yet is ugly and could have some unwanted inference with the notification window for example. (Bringing my window to the top will hide the notification window.)

Thank you on your time and suggestions!

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

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

发布评论

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

评论(1

找个人就嫁了吧 2024-09-12 18:49:01

TopMost,始终是一件棘手的事情。无法覆盖另一个将自身指定为 TopMost 的窗口。

Raymond Chen 有一篇关于此的好文章。

这个

TopMost, is always a tricky thing. There is no way to override another window that specifies itself as TopMost.

Raymond Chen has a good article on this.

Also a duplicate of this.

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