728x90
반응형
728x170
▶ RECT.cs
using System.Runtime.InteropServices;
namespace TestProject
{
/// <summary>
/// 사각형
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Public
#region Field
/// <summary>
/// 왼쪽
/// </summary>
public int Left;
/// <summary>
/// 위쪽
/// </summary>
public int Top;
/// <summary>
/// 오른쪽
/// </summary>
public int Right;
/// <summary>
/// 아래쪽
/// </summary>
public int Bottom;
#endregion
}
}
728x90
▶ WindowHelper.cs
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 윈도우 헬퍼
/// </summary>
public static class WindowHelper
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Import
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 윈도우 사각형 구하기 - GetWindowRect(windowHandle, rectangle)
/// <summary>
/// 윈도우 사각형 구하기
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
/// <param name="rectangle">사각형</param>
/// <returns>처리 결과</returns>
[DllImport("user32.dll")]
private static extern bool GetWindowRect(HandleRef windowHandle, [In, Out] ref RECT rectangle);
#endregion
#region 전경 윈도우 구하기 - GetForegroundWindow()
/// <summary>
/// 전경 윈도우 구하기
/// </summary>
/// <returns>전경 윈도우 핸들</returns>
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region 전경 전체 화면 여부 구하기 - IsForegroundFullScreen(screen)
/// <summary>
/// 전경 전체 화면 여부 구하기
/// </summary>
/// <param name="screen">화면</param>
/// <returns>전경 전체 화면 여부</returns>
public static bool IsForegroundFullScreen(Screen screen)
{
if(screen == null)
{
screen = Screen.PrimaryScreen;
}
RECT rectangle = new RECT();
GetWindowRect(new HandleRef(null, GetForegroundWindow()), ref rectangle);
return new Rectangle
(
rectangle.Left,
rectangle.Top,
rectangle.Right - rectangle.Left,
rectangle.Bottom - rectangle.Top
).Contains(screen.Bounds);
}
#endregion
#region 전경 전체 화면 여부 구하기 - IsForegroundFullScreen()
/// <summary>
/// 전경 전체 화면 여부 구하기
/// </summary>
/// <returns>전경 전체 화면 여부</returns>
public static bool IsForegroundFullScreen()
{
return IsForegroundFullScreen(null);
}
#endregion
}
}
300x250
▶ MainForm.cs
using System;
using System.Threading;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.testButton.Click += testButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 테스트 버튼 클릭시 처리하기 - testButton_Click(sender, e)
/// <summary>
/// 테스트 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void testButton_Click(object sender, EventArgs e)
{
Thread.Sleep(5000);
bool result = WindowHelper.IsForegroundFullScreen(Screen.AllScreens[0]);
MessageBox.Show($"첫번째 모니터에서 전경 윈도우의 전체 화면 모드 여부 : {result}");
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[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 |
[C#/WINFORM] 윈도우 텍스트 구하기 (0) | 2021.04.07 |
[C#/WINFORM] 윈도우 위치/크기/상태 구하기 (0) | 2021.04.07 |
[C#/WINFORM] SendKeys 클래스 : 키 코드 사용하기 (0) | 2021.04.03 |
[C#/WINFORM] SendKeys 클래스 : SendWait 정적 메소드를 사용해 ESC 키 누르기 (0) | 2021.04.03 |
[C#/WINFORM] k-평균 클러스터링(k-means clustering) 사용하기 (0) | 2021.03.11 |
댓글을 달아 주세요