How to get "Active signal resolution"?

** 146 Reputation points
2021-03-31T18:26:45.637+00:00

83349-asr.png

Windows development Windows API - Win32
Developer technologies C++
Developer technologies C#
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,606 Reputation points
    2021-04-01T02:54:11.547+00:00

    Please try the following code:

            private async Task<string> GetActiveSignalResolution()  
            {  
                var all = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector());  
                if (all != null)  
                {  
                    foreach (var info in all)  
                    {  
                        if (info.Kind == DeviceInformationKind.DeviceInterface)  
                        {  
                            var display = await DisplayMonitor.FromInterfaceIdAsync(info.Id);  
                            if (display != null)  
                            {  
                                var size = display.NativeResolutionInRawPixels;  
                                return size.Width.ToString() + " × " + size.Height.ToString();  
                            }  
                        }  
                    }  
                }  
                throw new NotSupportedException();  
            }  
    

    The code comes from this thread and it works for me after testing.

    Because this code uses the UWP API, you need to install a nuget package: Microsoft.Windows.SDK.Contracts


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.