728x90
반응형
728x170
▶ POINT.cs
using System.Runtime.InteropServices;
namespace TestProject
{
/// <summary>
/// 포인트
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Public
#region Field
/// <summary>
/// X
/// </summary>
public int X;
/// <summary>
/// Y
/// </summary>
public int Y;
#endregion
}
}
728x90
▶ RECTANGLE.cs
using System.Runtime.InteropServices;
namespace TestProject
{
/// <summary>
/// 사각형
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct RECTANGLE
{
//////////////////////////////////////////////////////////////////////////////////////////////////// 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
}
}
300x250
▶ MONITOR_INFO_EX.cs
using System.Runtime.InteropServices;
namespace TestProject
{
/// <summary>
/// 모니터 정보 확장
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)]
public struct MONITOR_INFO_EX
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Public
#region Field
/// <summary>
/// 크기
/// </summary>
public uint Size;
/// <summary>
/// 디스플레이 사각형
/// </summary>
public RECTANGLE DisplayRectangle;
/// <summary>
/// 작업 영역 사각형
/// </summary>
public RECTANGLE WorkingAreaRectangle;
/// <summary>
/// 플래그
/// </summary>
public uint Flag;
/// <summary>
/// 장치명
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public char[] DeviceName;
#endregion
}
}
▶ MonitorHelper.cs
using System;
using System.Runtime.InteropServices;
namespace TestProject
{
/// <summary>
/// 모니터 헬퍼
/// </summary>
public static class MonitorHelper
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Import
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 포인트에서 모니터 구하기 - MonitorFromPoint(point, flag)
/// <summary>
/// 포인트에서 모니터 구하기
/// </summary>
/// <param name="point">포인트</param>
/// <param name="flag">플래그</param>
/// <returns>모니터 핸들</returns>
[DllImport("user32", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr MonitorFromPoint(POINT point, uint flag);
#endregion
#region 모니터 정보 구하기 - GetMonitorInfo(monitorHandle, monitorInfo)
/// <summary>
/// 모니터 정보 구하기
/// </summary>
/// <param name="monitorHandle">모니터 핸들</param>
/// <param name="monitorInfo">모니터 정보</param>
/// <returns>처리 결과</returns>
[DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool GetMonitorInfo(IntPtr monitorHandle, ref MONITOR_INFO_EX monitorInfo);
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region 모니터 정보 구하기 - GetMonitorInformation(monitorHandle)
/// <summary>
/// 모니터 정보 구하기
/// </summary>
/// <param name="monitorHandle">모니터 핸들</param>
/// <returns>모니터 정보</returns>
public static MONITOR_INFO_EX GetMonitorInformation(IntPtr monitorHandle)
{
MONITOR_INFO_EX monitorInfo = new MONITOR_INFO_EX
{
Size = (uint)Marshal.SizeOf(typeof(MONITOR_INFO_EX))
};
GetMonitorInfo(monitorHandle, ref monitorInfo);
return monitorInfo;
}
#endregion
#region 모니터 정보 구하기 - GetMonitorInformation(point)
/// <summary>
/// 모니터 정보 구하기
/// </summary>
/// <param name="point">포인터</param>
/// <returns>모니터 정보</returns>
public static MONITOR_INFO_EX GetMonitorInformation(POINT point)
{
IntPtr monitorHandle = MonitorFromPoint(point, 0);
MONITOR_INFO_EX monitorInfo = GetMonitorInformation(monitorHandle);
return monitorInfo;
}
#endregion
}
}
▶ Program.cs
using System;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
private static void Main()
{
MONITOR_INFO_EX monitorInfo = MonitorHelper.GetMonitorInformation(new POINT { X = 0, Y = 0 });
Console.WriteLine(monitorInfo.DeviceName);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 반복자(Iterator)를 사용해 텍스트 파일 반대로 읽기 (0) | 2021.02.08 |
---|---|
[C#/COMMON] 모니터 수 구하기 (0) | 2021.02.08 |
[C#/COMMON] Enum 클래스 : GetValues 정적 메소드를 사용해 열거형 값 배열 구하기 (0) | 2021.02.07 |
[C#/COMMON] WeakReference 클래스 : 약한 참조 사용하기 (0) | 2021.02.07 |
[C#/COMMON] 모니터 정보 구하기 (0) | 2021.02.06 |
[C#/COMMON] Version 클래스 : 버전 비교하기 (0) | 2021.02.04 |
[C#/COMMON] MSI 파일 설치시 관리자 권한 상승하기 (0) | 2021.02.03 |
[C#/COMMON] 커서 표시하기/숨기기 (0) | 2021.02.02 |
[C#/COMMON] CTRL 키 비활성화/활성화하기 (0) | 2021.02.01 |
[C#/COMMON] 작업 표시줄(Taskbar) 숨기기/보여주기 (0) | 2021.02.01 |
댓글을 달아 주세요