title: How to SetWindowPos Z-order of a window to just under the activated window?
body: <p>I have a side-bar app (dialog Win forms app) that controls an associated IE browser using Watin automation.</p>
  
  <p>When the side-bar is activated I want to also bring the associated browser forward, <em>but I do not want the win forms app to lose focus</em>. </p>
  
  <p>I have tried many settings/variations of the following code, but the winforms app loses focus to the browser as soon as it is activated, so no buttons on the form can be pressed!</p>
  
  <pre><code>    private void BrowserControlForm_Activated(object sender, EventArgs e)
      {
          if (this.Browser != null)
          {
              SetWindowPos(this.Browser.hWnd, -1, this.Width, 0, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height, 0);
          }
      }
  </code></pre>
  
  <p><strong>Q. What is the correct way to place the other window just under (Z-order-wise) the current activated (Winforms) window?</strong></p>
  
  <p><em>The example code also resizes the browser take up the remainder of the screen, but that is not relevant to the problem.</em> More of the existing code would not assist in solving the problem.</p>
  
  <p><strong>Updates:</strong></p>
  
  <p>SWP_NOACTIVATE fails to bring the browser window forward at all:</p>
  
  <pre><code>SetWindowPos(this.CareCheckBrowser.hWnd, -1, this.Width, 0, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height, 0x0010 /*SWP_NOACTIVATE*/);
  </code></pre>
  
  <p>Insert after the current window's handle still loses focus:</p>
  
  <pre><code>SetWindowPos(this.Browser.hWnd, (int)this.Handle, this.Width, 0, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height, 0);
  </code></pre>
  
  <p>Setting the current window to the top after the browser does not work as the focus is already lost (so button clicks are still ignored). The focus/activation just flicks back and forth on any clicks e.g.:</p>
  
  <pre><code>SetWindowPos(this.Browser.hWnd, 0, this.Width, 0, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - this.Width, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height, 0x0004);
  SetForegroundWindow(this.Browser.hWnd);
  SetForegroundWindow(this.Handle);
  </code></pre>