DCSIMG
Get screen resolution in Windows 8 Metro style application - Essential XAML

Get screen resolution in Windows 8 Metro style application

Today, someone asked an interesting question in the Israeli Metro forum I’m moderating.

The question was: “How can I know what’s the screen resolution in a Metro style app?”

This is a tricky answer, since:

  1. This capability has been removed from the RC.
  2. We can’t rely on current window Width and Height, since it may not be fully opened (snapping).

Well, searching a bit over the API’s, I didn’t find anything that can help, but, we can always use DirectX.

Creating a C++ Metro style application, here’s a code snippet demonstrating how to extract the screen resolution of a given display device:

image

 

Using DirectX, we can query for the IDXGIAdapter, then make a call the EnumOutputs, which provides information for output devices. From there, we can make a call for IDXGIOutput::GetDesc to get the device description. From there we can extract the screen resolution.

Now, to be able getting this value from a C# or JS application, we should create a simple WinRT object, placing it in a WinRT dll, then use it from other projects.

To create a WinRT object with C++, we should create a class which looks like this:

image

 

Feel free to download the code (MetroScreenRes.zip) for both the WinRT object and a C# tester.

Running the application, you can click on the Button and see your screen resolution. Changing the resolution and click the button again, you may see it updated.

Published Tuesday, July 24, 2012 11:50 PM by Tomer Shamam

Comments

# re: Get screen resolution in Windows 8 Metro style application

Thursday, October 18, 2012 8:37 AM by meera

How to get screen size in inches for windows 8 app? Please do reply.

# re: Get screen resolution in Windows 8 Metro style application

Thursday, October 18, 2012 8:37 AM by meera

How to get screen size in inches for windows 8 app? Please do reply.

# re: Get screen resolution in Windows 8 Metro style application

Thursday, October 18, 2012 8:54 AM by Tomer Shamam

Hi meera,

Use this API: DisplayProperties.LogicalDpi.

msdn.microsoft.com/.../windows.graphics.display.displayproperties.logicaldpi

# re: Get screen resolution in Windows 8 Metro style application

Thursday, February 21, 2013 1:20 AM by Emmanuel Huna

Since the C++ project needs Win32, the TestApp can only be compiled in x86.  Does this mean that if we use this that the app cannot work on ARM, so it won't work on the Surface RT?

# re: Get screen resolution in Windows 8 Metro style application

Wednesday, April 24, 2013 1:42 AM by Tomer Shamam

No. It supposed to work with all builds.

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above:
Powered by Community Server (Commercial Edition), by Telligent Systems