Reputation: 350
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..
Upvotes: 1
Views: 639
Reputation: 562
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.
Upvotes: 1
Reputation: 35318
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.
Upvotes: 0