728x90
728x170
■ IWin32Window 인터페이스를 사용해 메시지 박스를 최상위로 표시하는 방법을 보여준다.
▶ WIN32Window.cs
using System;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// WIN32 윈도우
/// </summary>
public class WIN32Window : IWin32Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 윈도우 핸들
/// </summary>
private IntPtr windowHandle;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 윈도우 핸들 - Handle
/// <summary>
/// 윈도우 핸들
/// </summary>
public IntPtr Handle
{
get
{
return this.windowHandle;
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - WIN32Window(windowHandle)
/// <summary>
/// 생성자
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
public WIN32Window(IntPtr windowHandle)
{
this.windowHandle = windowHandle;
}
#endregion
}
}
▶ Program.cs
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Import
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 전경 윈도우 구하기 - GetForegroundWindow()
/// <summary>
/// 전경 윈도우 구하기
/// </summary>
/// <returns>윈도우 핸들</returns>
[DllImport("user32")]
private static extern IntPtr GetForegroundWindow();
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
private static void Main()
{
IntPtr windowHandle = GetForegroundWindow();
WIN32Window window = new WIN32Window(windowHandle);
MessageBox.Show(window, "작업을 진행하시겠습니까?", "확인", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
}
#endregion
}
}
728x90
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] Graphics 클래스 : FromHwnd 정적 메소드를 사용해 데스크톱 Graphics 객체 구하기 (0) | 2021.07.03 |
---|---|
[C#/WINFORM/.NET5] IProgress<T> 인터페이스 : Report 메소드를 사용해 비동기 작업시 진행 상태 보고하기 (0) | 2021.06.27 |
[C#/WINFORM] 누겟 설치 : ImageProcessor.Plugins.WebP (0) | 2021.05.17 |
[C#/WINFORM] 누겟 설치 : ImageProcessor (0) | 2021.05.17 |
[C#/WINFORM] OpenFileDialog 클래스 : AutoUpgradeEnabled 속성을 사용해 이전 스타일 대화 상자 열기 (0) | 2021.04.30 |
[C#/WINFORM] Bitmap 클래스 : 스크롤 가능한 육각형 몽타주 비트맵 사용하기 (0) | 2021.04.11 |
[C#/WINFORM] Bitmap 클래스 : 스크롤 가능한 대각선 몽타주 비트맵 사용하기 (0) | 2021.04.11 |
[C#/WINFORM] 측면 및 종횡비로 정의된 사각형 찾기 (0) | 2021.04.11 |
[C#/WINFORM] B 트리 사용하기 (0) | 2021.04.10 |
[C#/WINFORM] Bitmap 클래스 : 마우스 휠을 사용해 특정 종횡비로 비트맵 잘라내기 (0) | 2021.04.10 |