0

I have this:

                    Process process = new Process();
                    string VLCPath = ConfigurationManager.AppSettings["VLCPath"];
                    process.StartInfo.FileName = VLCPath;
                    process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                    process.Start();

But it wont start vlc maximized, what am I doing wrong? It keeps starting vlc in the state that I closed it the last time..

Bayern
  • 330
  • 3
  • 20

2 Answers2

1

You can set the Window state to maximize with Microsofts ShowWindow function.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_MAXIMIZE = 3;

var process = new Process();
process.StartInfo.FileName = ConfigurationManager.AppSettings["VLCPath"];
process.Start();
process.WaitForInputIdle();

int count = 0;
while (process.MainWindowHandle == IntPtr.Zero && count < 1000)
{
    count++;
    Task.Delay(10);
}

if  (process.MainWindowHandle != IntPtr.Zero)
{ 
    ShowWindow(process.MainWindowHandle, SW_MAXIMIZE);
}

You will need the while loop because WaitForInputIdle() only waits until the process has started up. So there is a high chance that the MainWindowHandle is not set yet.

Philipp H.
  • 552
  • 1
  • 3
  • 19
0

You can start a process and ask it politely to run maximized, but that doesn't mean the process has to heed your request. After all, it's a third-party process. If there is some logic in their code that stores the last window state on close and re-loads it on open, then you're out of luck.

rory.ap
  • 34,009
  • 10
  • 83
  • 174
  • Hmm makes sense, now I changed vlc interface to fullscreen. So now it alwats starts in fullscreen. But for notepad it works so I thought it could work for every process... – Bayern Mar 22 '17 at 11:27