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++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.