Search code examples
cwinapiwindows-7z-orderwindow-position

Placing a window after TOPMOST window


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?


Solution

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