Answered by:
minimize a System.Diagnostics.Process

Question
-
I have a System.Diagnostics.Process which I started. I would like to minimize it. How can I do this in C#?
I found this post, but it is for VB, and it looks like it uses COM. Neither of which I like.
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=611361&SiteID=1
If there is a pure C# .NET way to do this, that would be great.
~STuesday, October 17, 2006 5:30 PM
Answers
-
just set the WindowStyle to minimized
Example:
ProcessStartInfo theProcess = new ProcessStartInfo("filename.exe");
theProcess.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(theProcess);
Tuesday, October 17, 2006 5:32 PM -
If the process is already running...you will need the handle to send to ShowWindow API.
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
ShowWindow(yourHandle, 2);
Tuesday, October 17, 2006 7:13 PM -
Had to do this:
ShowWindow( proc.MainWindowHandle, 2 );
Thanks,
~STuesday, October 17, 2006 7:50 PM
All replies
-
just set the WindowStyle to minimized
Example:
ProcessStartInfo theProcess = new ProcessStartInfo("filename.exe");
theProcess.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(theProcess);
Tuesday, October 17, 2006 5:32 PM -
The process is already running. I tried doing this (for the sake of being thorough):
runningProc.StartInfo.WindowStyle = FormWindowState.Minimized;
but it did not work.
~STuesday, October 17, 2006 6:36 PM -
If the process is already running...you will need the handle to send to ShowWindow API.
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
ShowWindow(yourHandle, 2);
Tuesday, October 17, 2006 7:13 PM -
ShowWindow( proc.Handle, 2 );
seems to have no effect at all. For processes I tried notepad.exe, and gvim -f. The (-f) makes the call blocking. Both had the same results.
~STuesday, October 17, 2006 7:46 PM -
Had to do this:
ShowWindow( proc.MainWindowHandle, 2 );
Thanks,
~STuesday, October 17, 2006 7:50 PM -
Yep...that would be the handle...Tuesday, October 17, 2006 7:51 PM