1

I am trying to open google chrome with C# but I don't want to see it when it opens. I tried to add

process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;

but it does nothing. I found out that i can use parameters to lunch chrome like --new-window but beside new window, no other parameter is working. I tried to lunch it in other locations on the screen but it has no effect either. I tried to change the window size but it does nothing too.

When I lunch my chrome it always open in maximized window (although I don't pass him this argument), I couldn't figure out why it always run in maximized mode but I think that this is the reason why I cant move it or re-size the window.

How can I run chrome without seeing the window? minimized or even lunch it out of the screen will be great. Thank you for your help

MyNick
  • 536
  • 1
  • 9
  • 25

1 Answers1

1

At first be sure that chrome is loaded completely(its window is loaded, I don't have any idea about it in this time) then use this code to minimize it.

private const int SW_SHOWMINIMIZED = 2;

[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

private void hideChrome()
{
    Process proc;
    foreach (Process process in Process.GetProcesses())
    {
        if (process.ProcessName.Equals("chrome"))
            proc = process;
    }

    IntPtr hWnd = proc.MainWindowHandle;
    if (!hWnd.Equals(IntPtr.Zero))
    {
        ShowWindowAsync(hWnd, SW_SHOWMINIMIZED);
    }
}
Ali Sepehri.Kh
  • 2,468
  • 2
  • 18
  • 27
  • First of all thank you for your help, it worked. But, i am using chrome and i try to hide the process of the browser (not of the tabs), apparently there is only 1 process of the browser for all of my 4 windows that are currently open. When i use this function it minimize the last one that had focus. How can i minimize the second one? – MyNick Oct 15 '14 at 12:52
  • @user2462683: At first, I'm sorry I did it on firefox and copy that with no edit here :) Yes you are right, try [this](http://stackoverflow.com/questions/2531828/how-to-enumerate-all-windows-belonging-to-a-particular-process-using-net) to get all window handlers. – Ali Sepehri.Kh Oct 15 '14 at 13:21