개발/C#
# 콘솔 창 숨기는 방법
노마드
2021. 1. 25. 08:11
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace backgroundStart
{
class Program
{
[DllImport("Kernel32.dll")] // API 함수를 포함하고 있는 DLL
private static extern IntPtr GetConsoleWindow(); // API 함수 원형
[DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int cmdShow);
static void Main(string[] args)
{
Console.WriteLine("Press any key to hide me.");
Console.ReadKey();
IntPtr hWnd = GetConsoleWindow();
if(hWnd != IntPtr.Zero)
{
ShowWindow(hWnd, 0); // 숨긴다
Thread.Sleep(5000);
ShowWindow(hWnd, 1); // 보인다
}
Console.ReadKey();
}
}
}