title: ShellExecuteEx() force window to top z order
body: <p>I looking for a method for forcing windows to set the program I launch with <em>ShellExecuteEx()</em> in first in z order.</p>
  
  <p>The base of the problem is an issue with a machine (only one) and Google Chrome<br>
  When I launch Chrome from <em>ShellExecuteEx()</em> with this parameters :</p>
  
  <blockquote>
    <p><a href="http://www.google.fr" rel="nofollow">http://www.google.fr</a> --kiosk --fast-start --chrome-frame</p>
  </blockquote>
  
  <p>It doesn't display the window, but I see the Chrome icon flashing in the bar.</p>
  
  <p>I've tried to force the window by using <em>EnumWindows()</em> and <em>BringWindowToTop()</em> then <em>SetWindowPos()</em> with *HWND_TOPMOST* flag but this doesn't work for all programs I've tried.</p>
  
  <p>Actualy I get a <em>HWND</em> by comparing pids</p>
  
  <pre><code>BOOL CALLBACK   SetWindowToTopFromhProcess(HWND hwnd, LPARAM lParam)
  {
      HANDLE      hProcess = (HANDLE)lParam;
      DWORD       win_pid = 0;
      DWORD       pid = 0;
      char        buf[512];
  
      pid = GetProcessId(hProcess);
      GetWindowThreadProcessId(hwnd, &amp;win_pid);
      if (pid == win_pid &amp;&amp; pid != 0 &amp;&amp; win_pid != 0)
      {
          //SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
          BringWindowToTop(hwnd);
  
          memset(&amp;buf, 0, sizeof(buf));
          GetWindowText(hwnd, buf, sizeof(buf));
          printf("%s\n", buf);
  
          return (FALSE);
      }
      return (TRUE);
  }
  
  int                     my_function()
  {
      SHELLEXECUTEINFO    ExecuteInfo;
  
      ...
      ExecuteInfo.nShow = SW_SHOWNORMAL;
      ...
      if (ShellExecuteEx(&amp;ExecuteInfo))
          EnumWindows(SetWindowToTopFromhProcess, (LPARAM)ExecuteInfo.hProcess);
      ...
  }
  </code></pre>
  
  <p>By the way, I've realized that the window handle I getting from the pid is not always the handle I want. For example with mspaint.exe the window name I retrieve is "GDI+ Window", so it's not the good window because it's not the good pid.</p>
  
  <p>I've also tried a lot of nShow flags in the <em>SHELLEXECUTEINFO</em> structure who doesn't work.</p>
  
  <p>So how to get the good window handle ? Is there another way to force the program I run to display its main window?
  Or any idea ?</p>