title: Making a process started from a window the top most
body: <p>I have window which I show using the Show() method like</p>
  
  <pre><code> _win.Show();
  </code></pre>
  
  <p>and this window's <code>TopMost</code> is <code>true</code></p>
  
  <p>With in the window on a button click a new process is started to open a file in the respective viewer</p>
  
  <pre><code>    Process p = new Process();
      p.Exited += new EventHandler(p_Exited);
      p.StartInfo.FileName = @"somepath";
      p.EnableRaisingEvents = true;
      p.Start();
  
     void p_Exited(object sender, EventArgs e)
     {
  
     }
  </code></pre>
  
  <p>I wan't this process to be the topmost till closed . What I tried is </p>
  
  <pre><code>[DllImport("user32.dll")]
  static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
  static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
  static readonly IntPtr HWND_TOP =new IntPtr(0);
  const UInt32 SWP_NOSIZE = 0x0001;
  const UInt32 SWP_NOMOVE = 0x0002;
  const UInt32 SWP_SHOWWINDOW = 0x0040;
  </code></pre>
  
  <p>and used it below <code>p.Start();</code> as</p>
  
  <pre><code>SetWindowPos(p.MainWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
  </code></pre>
  
  <p>This doesn't seems to work for me as <code>_wnd</code> is still the <code>TopMost</code>. However if I set </p>
  
  <pre><code>_wnd.TopMost = false;
  </code></pre>
  
  <p>After the process get started (let say notepad.exe) the notepad window gets behind the <code>_wnd</code> but on clicking the notepad window it will be brought to front. But in this case I  need to monitor if the process ended and then reset <code>TopMost</code>. </p>
  
  <p>Any help is appreciated.</p>