I want to be able to start a default web browser of a client and to be able to minimize and maximize its window as I need it.
Currently if I do this:
var proc = Process.Start("http://www.google.com");
proc is null.
And if I do this:
var proc = new Process();
proc.StartInfo.FileName = "http://www.google.com";
proc.Start();
The proc isn't null, but when I try to minimize it, or maximize it, i get an exception:
No process is associated with this object.
This is my current code:
public class WebPageHelper
{
private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
private Process currentProcess;
public WebPageHelper(String url)
{
currentProcess = new Process();
currentProcess.StartInfo.FileName = url;
currentProcess.Start();
}
public void MaximizeWebPage()
{
IntPtr hWnd = currentProcess.MainWindowHandle;
if (!hWnd.Equals(IntPtr.Zero))
{
ShowWindowAsync(hWnd, SW_SHOWMAXIMIZED);
}
}
public void MinimizeWebPage()
{
IntPtr hWnd = currentProcess.MainWindowHandle;
if (!hWnd.Equals(IntPtr.Zero))
{
ShowWindowAsync(hWnd, SW_SHOWMINIMIZED);
}
}
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
}
Is there any solution to this?