private Monitor(User32.DISPLAY_DEVICE displayDevice) { // Check params in debug build ? _displayDevice = displayDevice; _displaySettings = new DisplaySettings(_displayDevice.DeviceName); }
/// <summary>Get all monitors attached to this box</summary> public static Monitor[] GetAllAttached(bool getDisabledMonitors) { List <Monitor> retVal = new List <Monitor>(); bool success = true; uint index = 0; while (success) { User32.DISPLAY_DEVICE displayDevice = new User32.DISPLAY_DEVICE(); displayDevice.cb = Marshal.SizeOf(displayDevice); success = User32.EnumDisplayDevices(null, index++, ref displayDevice, 0); if (success) { if ((displayDevice.StateFlags & User32.DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0) { retVal.Add(new Monitor(displayDevice)); } else if ((displayDevice.StateFlags & User32.DISPLAY_DEVICE_MIRRORING_DRIVER) == 0) { if (getDisabledMonitors) { // Check to see if the display isn't a mirroring device, but // has a monitor attached. This would represent a currently // inactive monitor User32.DISPLAY_DEVICE monitorInfo = new User32.DISPLAY_DEVICE(); monitorInfo.cb = Marshal.SizeOf(displayDevice); success = User32.EnumDisplayDevices(null, 0, ref monitorInfo, 0); if (success) { retVal.Add(new Monitor(displayDevice)); } } } } } _monitorInfo.Clear(); _monitorHandle.Clear(); if (!User32.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, new User32.EnumMonitorsDelegate(EnumMonitorCallback), IntPtr.Zero)) { throw new Win32Exception("EnumDisplayMonitors"); } for (int t = 0; t < retVal.Count; t++) { User32.MONITORINFOEX monitorInfo; if (!_monitorInfo.TryGetValue(retVal[t].DeviceName, out monitorInfo)) { continue; } retVal[t]._area = monitorInfo.rcMonitor; retVal[t]._workingArea = monitorInfo.rcWork; } return(retVal.ToArray()); }