How do I minimize my currently executing Console application?

  • Thread starter Thread starter GG
  • Start date Start date
G

GG

Is there a way to minimize my current console app?
Using this code but does not work

System.Diagnostics.Process
currentProcess=System.Diagnostics.Process.GetCurrentProcess();

currentProcess.StartInfo.WindowStyle=System.Diagnostics.ProcessWindowSty
le.Minimized;


Thanks
 
Try this test console application class, it will minimize the app, sleep two
seconds, then restore it.

using System;
using System.IO;

namespace ConsoleApplication1
{

class Class1
{

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool ShowWindow( IntPtr hWnd, int nCmdShow);
private const int SW_MINIMIZE = 6;
private const int SW_MAXIMIZE = 3;
private const int SW_RESTORE = 9;


[STAThread]
static void Main(string[] args)
{
IntPtr winHandle =
System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
ShowWindow( winHandle, SW_MINIMIZE);
System.Threading.Thread.Sleep(2000);
ShowWindow( winHandle, SW_RESTORE);

}
}
}
 
Back
Top