title: How to remove TOPMOST attribute from a window
body: <p>I have a Windows C++ app that creates two separate windows</p>
  
  <p>I need to be able to make one window topmost temporarily, and then later remove that attribute so that other windows can then overlay it.</p>
  
  <p>I've tried this code:</p>
  
  <pre><code>void setWindowAlwaysOnTop(const std::string&amp; windowTitle, bool onTop) {
      HWND hwnd = FindWindowA(NULL, windowTitle.c_str());
      HWND insertAfter;
      if (onTop) insertAfter = HWND_TOPMOST;  //set the window always-on-top    
      else insertAfter = HWND_BOTTOM; 
      SetWindowPos(hwnd, insertAfter, NULL, NULL, NULL, NULL, SWP_NOMOVE | SWP_NOSIZE);
  }
  </code></pre>
  
  <p>But if I have previously called this code with onTop true it  doesn't re-allow other windows to overlay the target window after I call it with onTop false.</p>
  
  <p>I've also tried calling the function from the target window itself rather that from a separate window but it still doesn't work.</p>
  
  <p>As far as I can see at  <a href="https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setwindowpos" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setwindowpos</a> it should work?</p>
  
  <p>Is that correct, or is there another way of achieving this?</p>