public static IEnumerable <ScreenInfo> GetScreenInfo()
        {
            var setupApiData = GetSetupApiData()
                               .ToDictionary(x => x.DevicePath, StringComparer.InvariantCultureIgnoreCase);

            var screenInfos = new List <ScreenInfo>();

            // We assume screen count hasn't changed in the meantime ;)
            var screenCount = setupApiData.Count;

            var displayDevice = new NativeMethods.DISPLAY_DEVICE();

            displayDevice.cb = Marshal.SizeOf(displayDevice);
            for (uint i = 0; i < screenCount; i++)
            {
                if (!NativeMethods.EnumDisplayDevices(null, i, ref displayDevice, 0))
                {
                    throw new IndexOutOfRangeException(Resources.ScreenVanished);
                }

                if (
                    !NativeMethods.EnumDisplayDevices(
                        displayDevice.DeviceName, 0, ref displayDevice, NativeMethods.EDD_GET_DEVICE_INTERFACE_NAME))
                {
                    throw new IndexOutOfRangeException(Resources.ScreenVanished);
                }

                var partialScreenInfo = setupApiData[displayDevice.DeviceID];

                // Format: \\.\DISPLAY0\Monitor0
                var gdiDeviceName = displayDevice.DeviceName;

                // Format: \\.\DISPLAY0
                var managedScreenInfo = Screen.AllScreens.Single(x => gdiDeviceName.StartsWith(x.DeviceName));

                var screenInfo = new ScreenInfo(partialScreenInfo, displayDevice.DeviceString, managedScreenInfo);
                screenInfos.Add(screenInfo);
            }

            return(screenInfos);
        }
        public static IEnumerable<ScreenInfo> GetScreenInfo()
        {
            var setupApiData = GetSetupApiData()
                .ToDictionary(x => x.DevicePath, StringComparer.InvariantCultureIgnoreCase);

            var screenInfos = new List<ScreenInfo>();

            // We assume screen count hasn't changed in the meantime ;)
            var screenCount = setupApiData.Count;

            var displayDevice = new NativeMethods.DISPLAY_DEVICE();
            displayDevice.cb = Marshal.SizeOf(displayDevice);
            for (uint i = 0; i < screenCount; i++)
            {
                if (!NativeMethods.EnumDisplayDevices(null, i, ref displayDevice, 0))
                {
                    throw new IndexOutOfRangeException(Resources.ScreenVanished);
                }

                if (
                    !NativeMethods.EnumDisplayDevices(
                        displayDevice.DeviceName, 0, ref displayDevice, NativeMethods.EDD_GET_DEVICE_INTERFACE_NAME))
                {
                    throw new IndexOutOfRangeException(Resources.ScreenVanished);
                }

                var partialScreenInfo = setupApiData[displayDevice.DeviceID];

                // Format: \\.\DISPLAY0\Monitor0
                var gdiDeviceName = displayDevice.DeviceName;

                // Format: \\.\DISPLAY0
                var managedScreenInfo = Screen.AllScreens.Single(x => gdiDeviceName.StartsWith(x.DeviceName));

                var screenInfo = new ScreenInfo(partialScreenInfo, displayDevice.DeviceString, managedScreenInfo);
                screenInfos.Add(screenInfo);
            }

            return screenInfos;
        }