How to keep my topmost window on top?

亡梦爱人 提交于 2019-12-28 07:01:09

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/3066082/how-to-keep-my-topmost-window-on-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!