Placing a window after TOPMOST window

611 Views Asked by At

I have a window which is TOPMOST and I have another (myWindow) window which I want to place behind the 1st one and I don't want the second window to be top most:

SetWindowPos(topMostWin, HWND_TOPMOST, left, top, width, height, flags);
LONG_PTR exstyle = ::GetWindowLongPtr(myWindow, GWL_EXSTYLE);
if (exstyle & WS_EX_TOPMOST)
{
    exstyle &= ~WS_EX_TOPMOST;
    if( ! ::SetWindowLongPtr(myWindow, GWL_EXSTYLE, exstyle))
    {
        LOG_ERROR();
    }
}
SetWindowPos(myWindow, topMostWin, left, top, width, height, flags);

But myWindow keep acting like top most window and when I check myWindow's WS_EX_TOPMOST property of the extended styles it is still turned on. Is it possible to turn off the top most bit even though I'm placing the window after a top most window?

2

There are 2 best solutions below

12
On BEST ANSWER

HWND_TOP will put your window at the top of the z-order behind any topmost windows.

0
On

As a result of the introduction of “topmost” windows, HWND_TOP now brings the window “as high in the Z-order as possible without violating the rule that topmost windows always appear above non-topmost windows”. What does this mean in practice?

  • If a window is topmost, then HWND_TOP puts it at the very top of the Z-order.
  • If a window is not topmost, then HWND_TOP puts it at the top of all non-topmost windows (i.e., just below the lowest topmost window, if any).

Note: The above discussion completely ignores the issue of owner and owned windows. I left them out because they would add a layer of complication that distracts from the main topic.

                                *Raymond Chen - The Old New Thing* 

link to Raymond's blog site

what is left to say? ...