我有一个控制台应用程序,我想在运行应用程序时将控制台最小化(而不是永久隐藏),这可能吗? 此外,我正在使用定时器每10分钟运行任务,是否可以在每次应用程序运行时最小化控制台? 谢谢!
我有一个控制台应用程序,我想在运行应用程序时将控制台最小化(而不是永久隐藏),这可能吗? 此外,我正在使用定时器每10分钟运行任务,是否可以在每次应用程序运行时最小化控制台? 谢谢!
internal class Program
{
[DllImport("User32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool ShowWindow([In] IntPtr hWnd, [In] int nCmdShow);
private static void Main(string[] args)
{
IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
ShowWindow(handle, 6);
Console.ReadLine();
}
}
6
对应于 SW_MINIMIZE
。 - David Gardiner