Вот пример вызовов WinAPI для получения информации(разрешение, область в виртуальном мониторе) для всех мониторов(в многомониторной конфигурации).
Запускать MonitorInfo.FindMonitors();
using System;
using System.Runtime.InteropServices;
namespace MonitorInfoWinAPI
{
public class MonitorInfo
{
private static IntPtr hDesktop;
private static bool EnumerateMonitors(IntPtr hDesktop, IntPtr hdc, ref Rect pRect, int dwData)
{
MonitorInfo.hDesktop = hDesktop;
MonitorInfoEx info = new MonitorInfoEx();
GetMonitorInfo(hDesktop, info);
Console.WriteLine("Monitor {0}", new string(info.szDevice));
Console.WriteLine(" resolution {0}x{1}", info.rcMonitor.right, info.rcMonitor.bottom);
Console.WriteLine(" virtual monitor left top {0}x{1}", info.rcWork.left, info.rcMonitor.top);
Console.WriteLine(" virtual monitor right bottom {0}x{1}", info.rcWork.right, info.rcMonitor.bottom);
Console.WriteLine();
return true;
}
public static void FindMonitors()
{
EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, EnumerateMonitors, IntPtr.Zero);
return;
}
public delegate bool EnumMonitorsDelegate(IntPtr hDesktop, IntPtr hdc, ref Rect pRect, int dwData);
#region DLLImport
[DllImport("user32.dll")]
public static extern bool ClientToScreen(IntPtr hWnd, ref Point lpPoint);
[DllImport("user32.dll")]
public static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, EnumMonitorsDelegate lpfnEnum, IntPtr dwData);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern bool GetMonitorInfo(IntPtr hmonitor, [In, Out]MonitorInfoEx info);
#endregion
#region Structs
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)]
public class MonitorInfoEx
{
public int cbSize = Marshal.SizeOf(typeof(MonitorInfoEx));
public Rect rcMonitor = new Rect();
public Rect rcWork = new Rect();
public int dwFlags = 0;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public char[] szDevice = new char[32];
}
[StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int X;
public int Y;
}
#endregion
}
}