Advertisement

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

Started by June 19, 2017 07:39 AM
1 comment, last by SoldierOfLight 7 years, 7 months ago

Hello!

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? :)

According to https://msdn.microsoft.com/en-us/library/windows/desktop/bb174549(v=vs.85).aspx:

Quote

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

 

This topic is closed to new replies.

Advertisement