#region 隐藏窗口
[DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
private static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
public static void WindowHide(string consoleTitle)
{
IntPtr a = FindWindow("ConsoleWindowClass", consoleTitle);
if (a != IntPtr.Zero)
ShowWindow(a, 0);//隐藏窗口
else
throw new Exception("can't hide console window");
}
#endregion
调用方
//WindowHide(System.Console.Title);
WindowHide(System.Console.Title);
[DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
private static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
public static void WindowHide(string consoleTitle)
{
IntPtr a = FindWindow("ConsoleWindowClass", consoleTitle);
if (a != IntPtr.Zero)
ShowWindow(a, 0);//隐藏窗口
else
throw new Exception("can't hide console window");
}
#endregion
调用方
//WindowHide(System.Console.Title);
WindowHide(System.Console.Title);