title: C# get parent process from window handle
body: <p>I have a C# windows application and ultimately launches a dialog from an interop component.
  The problem is that this dialog window sometimes appears behind the c# application's main window, forcing a user to alt-tab to find it.</p>
  
  <p>I've put measures into place to find this dialog window and bring it forward...</p>
  
  <pre><code>private static extern bool SetForegroundWindow(IntPtr hWnd);
  
  public class SearchData
  {
      public string Wndclass;
      public string Title;
      public IntPtr hWnd;
  }
  
  private static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, ref SearchData data);
  private delegate bool EnumWindowsProc(IntPtr hWnd, ref SearchData data);
  
  public static bool EnumProc(IntPtr hWnd, ref SearchData data)
  {
    //Code to determine whether the window from handle hWnd is our target window.
    //apply handle, title, class to data and halt the enumeration
  }
  </code></pre>
  
  <p>...but 'finding' the dialog is problematic as the dialog's className and form title changes.</p>
  
  <p>However, the dialog window's parent process (Task Manager>Go To Process) is the same as the current process.  So to correctly 'find' this dialog window, my aim is to enumerate through all the windows, find the parent processID and compare against CurrentProcess.</p>
  
  <p>Is there a way to obtain the overall parent process from a window handle?</p>