#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);
c# 隐藏控制台窗口
最新推荐文章于 2024-08-27 17:42:52 发布