Ejemplo n.º 1
0
        /// <summary>
        /// Gets display monitor information.
        /// </summary>
        /// <returns>Array of display monitor information</returns>
        public static async Task <DisplayItem[]> GetDisplayMonitorsAsync()
        {
            const string deviceInstanceIdKey = "System.Devices.DeviceInstanceId";

            try
            {
                var devices = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector(), new[] { deviceInstanceIdKey });

                if (devices?.Any() == true)
                {
                    var items = new List <DisplayItem>(devices.Count);
                    foreach (var device in devices)
                    {
                        if (!device.Properties.TryGetValue(deviceInstanceIdKey, out object value))
                        {
                            continue;
                        }

                        var deviceInstanceId = value as string;
                        if (string.IsNullOrWhiteSpace(deviceInstanceId))
                        {
                            continue;
                        }

                        var displayMonitor = await DisplayMonitor.FromInterfaceIdAsync(device.Id);

                        //var displayMonitor = await DisplayMonitor.FromIdAsync(deviceInstanceId);
                        if (displayMonitor is null)
                        {
                            continue;
                        }

                        //Debug.WriteLine($"DeviceInstanceId: {deviceInstanceId}");
                        //Debug.WriteLine($"DeviceName: {device.Name}");
                        //Debug.WriteLine($"DisplayName: {displayMonitor.DisplayName}");
                        //Debug.WriteLine($"ConnectionKind: {displayMonitor.ConnectionKind}");
                        //Debug.WriteLine($"PhysicalConnector: {displayMonitor.PhysicalConnector}");
                        //Debug.WriteLine($"PhysicalSize: {GetDiagonal(displayMonitor.PhysicalSizeInInches):F1}");

                        items.Add(new DisplayItem(
                                      deviceInstanceId: deviceInstanceId,
                                      displayName: displayMonitor.DisplayName,
                                      isInternal: (displayMonitor.ConnectionKind == DisplayMonitorConnectionKind.Internal),
                                      connectionDescription: GetConnectionDescription(displayMonitor.ConnectionKind, displayMonitor.PhysicalConnector),
                                      physicalSize: GetDiagonal(displayMonitor.PhysicalSizeInInches)));
                    }
                    return(items.ToArray());
                }
            }
            catch (ArgumentException ax) when((uint)ax.HResult == ERROR_INVALID_PARAMETER)
            {
            }
            catch (Exception ex) when((uint)ex.HResult == ERROR_GEN_FAILURE)
            {
            }
            return(Array.Empty <DisplayItem>());
        }
Ejemplo n.º 2
0
        private static async Task <List <DisplayMonitor> > GetMonitorInfosAsync()
        {
            var deviceInfos = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector());

            List <DisplayMonitor> monitors = new();

            foreach (var deviceInfo in deviceInfos)
            {
                DisplayMonitor monitor = await DisplayMonitor.FromInterfaceIdAsync(deviceInfo.Id);

                monitors.Add(monitor);
            }
            return(monitors);
        }
        private async Task <DisplayMonitor> GetMonitorInfoAsync()
        {
            var deviceInfos = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector());

            foreach (var deviceInfo in deviceInfos)
            {
                if (deviceInfo.Id == Id)
                {
                    var monitor = await DisplayMonitor.FromInterfaceIdAsync(deviceInfo.Id);

                    return(monitor);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets display monitor information.
        /// </summary>
        /// <returns>Array of display monitor information</returns>
        public static async Task <DisplayItem[]> GetDisplayMonitorsAsync()
        {
            const string deviceInstanceIdKey = "System.Devices.DeviceInstanceId";

            try
            {
                var devices = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector(), new[] { deviceInstanceIdKey });

                if (devices is { Count : > 0 })
                {
                    var items = new List <DisplayItem>(devices.Count);
                    foreach (var device in devices)
                    {
                        if (!device.Properties.TryGetValue(deviceInstanceIdKey, out object value))
                        {
                            continue;
                        }

                        var deviceInstanceId = value as string;
                        if (string.IsNullOrWhiteSpace(deviceInstanceId))
                        {
                            continue;
                        }

                        var displayMonitor = await DisplayMonitor.FromInterfaceIdAsync(device.Id);

                        //var displayMonitor = await DisplayMonitor.FromIdAsync(deviceInstanceId);
                        if (displayMonitor is null)
                        {
                            continue;
                        }

                        //Debug.WriteLine($"DeviceInstanceId: {deviceInstanceId}");
                        //Debug.WriteLine($"DisplayName: {displayMonitor.DisplayName}");
                        //Debug.WriteLine($"ConnectionKind: {displayMonitor.ConnectionKind}");
                        //Debug.WriteLine($"PhysicalConnector: {displayMonitor.PhysicalConnector}");
                        //Debug.WriteLine($"PhysicalSize: {GetDiagonal(displayMonitor.PhysicalSizeInInches):F1}");

                        items.Add(new DisplayItem(
                                      deviceInstanceId: deviceInstanceId,
                                      displayName: displayMonitor.DisplayName,
                                      isInternal: (displayMonitor.ConnectionKind == DisplayMonitorConnectionKind.Internal),
                                      connectionDescription: GetConnectionDescription(displayMonitor.ConnectionKind, displayMonitor.PhysicalConnector),
                                      physicalSize: GetDiagonal(displayMonitor.PhysicalSizeInInches)));
                    }
                    return(items.ToArray());
                }
            }
Ejemplo n.º 5
0
        /*
         *  GET EACH DisplayMonitor OBJECT from the DeviceInformation of the device interface ID,
         *  then acquire its descriptor (in this case, EDID).
         */
        public async void EnumDisplay()
        {
            for (var index = 0; index < deviceList.Count; index++)
            {
                if (index != 0)
                {
                    Console.WriteLine();
                }

                DisplayMonitor display = await DisplayMonitor.FromInterfaceIdAsync(deviceList[index].Id);

                byte[] EDID = display.GetDescriptor(DisplayMonitorDescriptorKind.Edid);

                string hexBuffer = BitConverter.ToString(EDID).Replace("-", " ").ToLower();
                Console.WriteLine(string.Format("{0} : {1}", deviceList[index].Name, deviceList[index].Id));
                Console.Write(hexBuffer + "\n");
            }
        }
Ejemplo n.º 6
0
        private async Task TestAsync()
        {
            var selector = DisplayMonitor.GetDeviceSelector();
            var infos    = await DeviceInformation.FindAllAsync(selector);

            var monitors = new List <DisplayMonitor>();

            foreach (var info in infos)
            {
                var monitor = await DisplayMonitor.FromInterfaceIdAsync(info.Id);

                monitors.Add(monitor);
            }

            var output = new List <string>();

            foreach (var monitor in monitors)
            {
                output.Add($"RawDpiX: {monitor.RawDpiX}    RawDpiY: {monitor.RawDpiY}    Width: {monitor.NativeResolutionInRawPixels.Width}    Height: {monitor.NativeResolutionInRawPixels.Height}");
            }
            MainListView.ItemsSource = output;
        }
Ejemplo n.º 7
0
        //[SupportedOSPlatform("Windows10.0.17134.0")]
        public async void UseDeviceApi()
        {
            if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 17134, 0))
            {
                var deviceInformations = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector());

                foreach (DeviceInformation device in deviceInformations)
                {
                    DisplayMonitor displayMonitor = await DisplayMonitor.FromInterfaceIdAsync(device.Id);

                    // Print some info about the display monitor
                    var x = "DisplayName: " + displayMonitor.DisplayName;
                    var y = "ConnectionKind: " + displayMonitor.ConnectionKind;


                    if (OperatingSystem.IsWindowsVersionAtLeast(10, 0, 19041, 0))
                    {
                        var z = "IsDolbyVisionSupported: " + displayMonitor.IsDolbyVisionSupportedInHdrMode;
                    }
                }
            }
        }