title: Combining CreateProcess and AllowSetForegroundWindow on WIN32
body: <p>I have an application that is essentially a "helper" application that wraps another app.</p>
  
  <p>The app that the user interacts with is a process that is created by the "helper" app like so:</p>
  
  <pre><code>PROCESS_INFORMATION processInfo;
  STARTUPINFO startupInfo;
  memset(&amp;processInfo, 0, sizeof(processInfo));
  memset(&amp;startupInfo, 0, sizeof(startupInfo));
  startupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
  startupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  startupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
  startupInfo.dwFlags = STARTF_USESTDHANDLES;
  startupInfo.cb = sizeof(startupInfo);
  int retval = CreateProcess(cmd, cmdLine, NULL, NULL, false,
      CREATE_NO_WINDOW, NULL, NULL, &amp;startupInfo,
      &amp;processInfo);
  </code></pre>
  
  <p>This process is an executable that I do not have the source code to and cannot make changes to.</p>
  
  <p>The "helper" application does a few things based mainly on network traffic from the other app.  At one point I want to display a file browse dialog from the helper app based on something the user does in the started UI process.</p>
  
  <p>When I show the file dialog from the helper app, it's shown behind the UI of the process that was created, which isn't ideal.  I tried calling SetForegroundWindow() from the helper app but it fails the criteria specified for SetForegroundWindow in the MSDN docs ( <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx</a> ), namely:</p>
  
  <p>The process is not the foreground process.</p>
  
  <p>The process was not started by the foreground process.</p>
  
  <p>(even though the process created the foreground process).</p>
  
  <p>Is there a way to call CreateProcess() with a flag or setting that works like calling AllowSetForegroundWindow() from that process?  Or a flag that can be used to make Windows think the started process is "the same" as the process that started it for purposes of SetForegroundWindow permissions?</p>
  
  <p>Or is there another way I can show the dialog generated by the helper app on top of the created process' dialogs?</p>