Tag: winrt

How to get supported display modes using SharpDX

Below is a short bit of code that will use SharpDX to enumerate the valid display modes on all adapters (video cards) and all outputs (monitors) for the computer that is hosting the application.

There are a few caveats with this:

  • Do not run this if you are using the Windows RT device simulator from Visual Studio 2012 or you will get exceptions (remote/virtualized instances aren’t supported by some of the DirectX used here)
  • This only shows interlaced and scaling display modes (there are Stereo and StereoDisabled modes for some outputs)
  • Keep in mind that this is every adapter and output on your computer, so if you want just the default adapter, you’ll have to make some changes
  • Windows Store Apps are always in full screen, so any display mode that you apply to the active device where the resolution is less than the desktop resolution is going to look stretched (there are reasons to do this, however)
SharpDX.DXGI.Factory1 dxgiFactory = new SharpDX.DXGI.Factory1();
foreach (var dxgiAdapter in dxgiFactory.Adapters)
    foreach (var output in dxgiAdapter.Outputs)
        foreach (var format in Enum.GetValues(typeof(SharpDX.DXGI.Format)))
            var displayModes = output.GetDisplayModeList(
                | SharpDX.DXGI.DisplayModeEnumerationFlags.Scaling

            foreach (var displayMode in displayModes)
                if (displayMode.Scaling == SharpDX.DXGI.DisplayModeScaling.Unspecified)
                    int displayWidth = displayMode.Width;
                    int displayHeight = displayMode.Height;
                    Rational displayRefresh = displayMode.RefreshRate;


Read more