Make process window visible/Invisble in .NET

Vishal picture Vishal · Jul 27, 2011 · Viewed 12.7k times · Source

I have my application, in which I am starting a new process. But I need to resize the window in the process to fit into my requirement. But first the process opens the window in normal size and then I resize it to fit. This make it look odd. So can I start the process with the winodw in invisible mode and then resize and then make it visible?

ProcessStartInfo startInfo = new ProcessStartInfo("myApp.exe");
MyApp = Process.Start(startInfo);
Thread.Sleep(2000);
MoveWindow(MyApp.MainWindowHandle, 0, 380, 2040, 1150, true);

Answer

Cipi picture Cipi · Jul 27, 2011

Tried startInfo.WindowStyle = ProcessWindowStyle.Hidden; before .Start() call to hide it? And then use your code to show it?

Like this:

ProcessStartInfo startInfo = new ProcessStartInfo("myApp.exe");

startInfo.WindowStyle = ProcessWindowStyle.Hidden;

MyApp = Process.Start(startInfo);
Thread.Sleep(2000);
MoveWindow(MyApp.MainWindowHandle, 0, 380, 2040, 1150, true);

To show the window import this method:

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

Then call it after MoveWindow function:

ShowWindow(MyApp.MainWindowHandle, 5);