How to keep my topmost window on top? [duplicate]
Asked Answered
R

1

6

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!

Rattan answered 17/6, 2010 at 22:18 Comment(0)
M
8

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.

Mispleading answered 17/6, 2010 at 22:21 Comment(1)
Chen's article isn't any good. I as a user want only one program doing it. I will never start 2 such programs at one time. So even if the Universe collapses when two programs try to be the topmostest simultaneously, I don't care.Byrnes

© 2022 - 2024 — McMap. All rights reserved.