Sign in to follow this  

[SharpDX] [DXGI] Trying to get the current display mode

Recommended Posts

Posted (edited)


I am trying to get the current display mode resolution, refresh rate and pixel format with the following code:

var bounds = output.Description.DesktopBounds;
var mode = new ModeDescription
    Width = bounds.Right - bounds.Left,
    Height = bounds.Bottom - bounds.Top

output.GetClosestMatchingMode(device, mode, out ModeDescription match);

Here 'output' is the current output device. My first question is if the above code is correct? My assumption is that I can compute the current display mode resolution from the desktop bounds returned for the current output. Does that make any sense at all or is there a better way to do so? Then I call 'GetClosestMatchingMode' to get the current display mode, assuming that if I let the pixel format and refresh rate unspecified (all zeroed out), the function would fill them out with the values from the current display mode. Is my assumption correct? The above code seems to work fine on my machine, but that might just be a coincidence.

My second question is related to a particular error I am receiving. When calling 'GetDisplayModeList' and 'GetClosestMatchingMode' on my own desktop everything seems to work just fine. However, when accessing my PC via a remote desktop both methods would throw an exception with DXGI error 'DXGI_ERROR_NOT_CURRENTLY_AVAILABLE'. Is that expected or I am doing something wrong? My current workaround is to simply catch the exception and deal with it by assuming the available display modes cannot be determined, except for the current desktop resolution computed from the output bounds.

Any advice or insight regarding this would be greatly appreciated!

By the way, I have noticed that posting a code block would render it with black text on black background on my Chrome browser, making it extremely difficult to read, unless I copy-paste it to Notepad. Seems like a broken CSS perhaps? :)

Edited by vanka78bg

Share this post

Link to post
Share on other sites
Posted (edited)

According to


If GetDisplayModeList is called from a Remote Desktop Services session (formerly Terminal Services session), DXGI_ERROR_NOT_CURRENTLY_AVAILABLE is returned.


Edited by SoldierOfLight

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this