public Win32Monitor(DisplayDeviceW adapter, DisplayDeviceW?display) { Name = display != null ? display.Value.DeviceString : adapter.DeviceString; AdapterName = adapter.DeviceName; DeviceName = display == null ? "<<Unknown Device>>" : display.Value.DeviceName; Debug.Assert(Name != null); var dm = new DeviceMode(); dm.dmSize = (short)Marshal.SizeOf(dm); User32.EnumDisplaySettingsW(adapter.DeviceName.PadRight(32, '\0'), (int)DisplaySettings.CurrentSettings, ref dm); Win32Platform.CheckError("Enumerating display settings."); Width = dm.dmPelsWidth; Height = dm.dmPelsHeight; IntPtr dc = Gdi32.CreateDCW("DISPLAY", adapter.DeviceName, null, IntPtr.Zero); Debug.Assert(dc != IntPtr.Zero); if (Win32Platform.IsWindows81OrGreater) { WidthPhysical = Gdi32.GetDeviceCaps(dc, DeviceCap.HorizontalSize); HeightPhysical = Gdi32.GetDeviceCaps(dc, DeviceCap.VertSize); } else { WidthPhysical = (int)(dm.dmPelsWidth * 25.4f / Gdi32.GetDeviceCaps(dc, DeviceCap.LogPixelsX)); HeightPhysical = (int)(dm.dmPelsHeight * 25.4f / Gdi32.GetDeviceCaps(dc, DeviceCap.LogPixelsY)); } Gdi32.DeleteDC(dc); if ((adapter.StateFlags & DisplayDeviceStateFlags.ModesPruned) != 0) { ModesPruned = true; } var rect = new Rect { Left = dm.dmPosition.X, Top = dm.dmPosition.Y, Right = dm.dmPosition.X + dm.dmPelsWidth, Bottom = dm.dmPosition.Y + dm.dmPelsHeight }; User32.EnumDisplayMonitors(IntPtr.Zero, ref rect, MonitorCallback, null); Win32Platform.CheckError("Creating monitor."); }