title: Maximize or Restore a Window doesn't work
body: <p>I have a windows form which checks whether a process is minimized or not. If it is it should maximize it and bring the window to front. If the window is not maximized and is in the background the code is working properly and the window comes to the front. But when I check for isiconic i.e minimized it doesn't restore or maximize the window. My code is </p>
  
  <pre><code>[DllImport("user32.dll", CharSet = CharSet.Auto)]
          [return: MarshalAs(UnmanagedType.Bool)]
          private static extern
              bool SetForegroundWindow(IntPtr hWnd);
          [DllImport("user32.dll", CharSet = CharSet.Auto)]
          [return: MarshalAs(UnmanagedType.Bool)]
          private static extern
              bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
          [DllImport("user32.dll")]
          private static extern
              bool IsIconic(IntPtr hWnd);
          [DllImport("user32.dll")]
          private static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
          [DllImport("user32.dll", SetLastError = true)]
          [return: MarshalAs(UnmanagedType.Bool)]
          static extern bool PrintWindow(IntPtr hWnd, IntPtr hDC, uint nFlags);
  
          private const int SW_HIDE = 0;
          private const int SW_SHOWNORMAL = 1;
          private const int SW_SHOWMINIMIZED = 2;
          private const int SW_SHOWMAXIMIZED = 3;
          private const int SW_SHOWNOACTIVATE = 4;
          private const int SW_RESTORE = 9;
          private const int SW_SHOWDEFAULT = 10;
          public Form1()
          {
              InitializeComponent();
              this.Hide();
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {            
              this.Visible = false;
  
              Process[] processes = Process.GetProcesses();            
              foreach (var process in Process.GetProcessesByName("Connectivity.VaultPro"))
              {
                  IntPtr hWnd = process.MainWindowHandle;
                  // if iconic, we need to restore the window
                  if (IsIconic(hWnd))
                  {
                      //ShowWindowAsync(hWnd, SW_RESTORE);
                      ShowWindow(hWnd, SW_RESTORE);
                      //SetForegroundWindow(hWnd);
                  }
                  else
                  {
                      ShowWindowAsync(hWnd, SW_RESTORE);                    
                      SetForegroundWindow(hWnd);
                  }
                  // bring it to the foreground
                  SetForegroundWindow(hWnd);
  
              }
  
  
  
              if (Directory.Exists(@"C:\Temp"))
              {
                  if (File.Exists(@"C:\Temp\temp.png"))
                  {
                      File.Delete(@"C:\Temp\temp.png");
                  }
              }
              else
              {
                  Directory.CreateDirectory(@"C:\Temp");
              }
  }
  </code></pre>
  
  <p>In the if condition I have tried it with ShowWindow and have also tried it with SW_SHOWMAXIMIZED and SW_RESTORE. Can someone tell me what may be the problem in the code?
  Thanks in advance</p>