728x90
반응형
728x170
▶ Program.cs
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Import
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 콘솔 윈도우 구하기 - GetConsoleWindow()
/// <summary>
/// 콘솔 윈도우 구하기
/// </summary>
/// <returns>콘솔 윈도우 핸들</returns>
[DllImport("kernel32.dll")]
private static extern IntPtr GetConsoleWindow();
#endregion
#region 시스템 메뉴 구하기 - GetSystemMenu(windowHandle, revert)
/// <summary>
/// 시스템 메뉴 구하기
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
/// <param name="revert">메뉴 복사 핸들 여부</param>
/// <returns>시스템 메뉴 핸들</returns>
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr windowHandle, bool revert);
#endregion
#region 메뉴 항목 이용 가능 여부 설정하기 - EnableMenuItem(menuHandle, menuItemID, enabled)
/// <summary>
/// 메뉴 항목 이용 가능 여부 설정하기
/// </summary>
/// <param name="menuHandle">메뉴 핸들</param>
/// <param name="menuItemID">메뉴 항목 ID</param>
/// <param name="enabled">이용 가능 여부</param>
/// <returns>처리 결과</returns>
[DllImport("user32.dll")]
private static extern bool EnableMenuItem(IntPtr menuHandle, uint menuItemID, uint enabled);
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// SC_CLOSE
/// </summary>
private const uint SC_CLOSE = 0xf060;
/// <summary>
/// MF_ENABLED
/// </summary>
private const uint MF_ENABLED = 0x00000000;
/// <summary>
/// MF_GRAYED
/// </summary>
private const uint MF_GRAYED = 0x00000001;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
private static void Main()
{
Console.Title = "콘솔(Console) 닫기 버튼 비활성화 하기";
IntPtr consoleWindowHandle = GetConsoleWindow();
SetCloseButtonEnabled(consoleWindowHandle, false);
Console.WriteLine("닫기 버튼을 비활성화 했습니다.");
Thread.Sleep(3000);
SetCloseButtonEnabled(consoleWindowHandle, true);
Console.WriteLine("닫기 버튼을 활성화 했습니다.");
Console.WriteLine("프로그램을 종료하기 위해 아무 키나 눌러 주시기 바랍니다.");
Console.ReadKey(true);
}
#endregion
#region 닫기 버튼 이용 가능 여부 설정하기 - SetCloseButtonEnabled(windowHandle, enabled)
/// <summary>
/// 닫기 버튼 이용 가능 여부 설정하기
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
/// <param name="enabled">이용 가능 여부</param>
private static void SetCloseButtonEnabled(IntPtr windowHandle, bool enabled)
{
IntPtr systemMenuHandle = GetSystemMenu(windowHandle, false);
EnableMenuItem(systemMenuHandle, SC_CLOSE, (uint)(MF_ENABLED | (enabled ? MF_ENABLED : MF_GRAYED)));
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] CodeDomProvider 클래스 : 런타임에서 C# 코드를 동적으로 컴파일하고 DLL 파일 생성하기 (0) | 2018.04.26 |
---|---|
[C#/COMMON] CSharpCompilation 클래스 : 런타임에서 C# 코드를 동적으로 컴파일하기 (0) | 2018.04.26 |
[C#/COMMON] Stream 클래스 : 스로틀(Throttle) 스트림 만들기 (0) | 2018.04.09 |
[C#/COMMON] 특정 파일을 사용하는 프로세스 리스트 구하기 (0) | 2018.03.29 |
[C#/COMMON] 사용자 계정 변경하기 (0) | 2018.03.24 |
[C#/COMMON] 디버그 모드에서 프로세스 참조 구하기 (0) | 2018.03.15 |
[C#/COMMON] ITypedList 인터페이스 : TypedCollection<T> 만들기 (0) | 2018.03.11 |
[C#/COMMON] BitConverter : ToString 정적 메소드를 사용해 바이트 배열에서 문자열 구하기 (0) | 2018.03.04 |
[C#/COMMON] FileAttributes 클래스 : 디렉토리 여부 구하기 (0) | 2018.03.04 |
[C#/COMMON] 숫자 포맷 문자열 사용하기 (0) | 2018.03.04 |
댓글을 달아 주세요