# 콘솔 창 숨기는 방법

2021. 1. 25. 08:11개발/C#

 

 

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();

    }

  }

}

'개발 > C#' 카테고리의 다른 글

# 메뉴 고르기 프로그램 예제 코드  (0) 2021.01.25
# 알람 시계 만들기  (0) 2021.01.25
# 네이버 크롤러 예제 코드  (0) 2021.01.25
# CodeLens (코드렌즈)  (0) 2021.01.25
# 접근 제한자 (접근 한정자)  (0) 2021.01.25