Search code examples
winapifullscreenresolutiondirectx-11dpi-aware

Weird desktop resolution after DX11 setting fullscreen state


I have a DPI Aware application(via manifest file) and on 1 monitor system all the the following methods are returning wrong desktop resolution:

  • GetSystemMetrics
  • GetMonitorInfo
  • GetWindowRect(GetDesktopWindow(), &desktop)
  • EnumDisplaySettingsExA/ENUM_CURRENT_SETTINGS
  • IDXGIOutput::GetDesc

My monitor is 4k but I set desktop size to 1920x1080 with 100% scale. When in windowed mode the reported resolution via all the methods is correct. However when switched to full-screen they all return 1600x1200. If it was DPI Aware problem it should at least keep the aspect ratio, e.g. 1600x900.

I noticed that the wrong results are after a call to IDXGISwapChain::SetFullscreenState(true, output_device) where the swap chain object is created with the flag DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH as per MSDN.

The app is using DirectX 11.

Any suggestions what my cause this?

Thank you


Solution

  • So I found the issue - the IDXGISwapChain::ResizeTarget(mode) which need to be resized before going to fullscreen was with wrong resolution(due to previous windowed mode with custom size). This caused IDXGISwapChain::SetFullscreenState(true, output_device)to switch to different strange desktop resolutions depending on what happened to be the size of the DX targets. Setting the targets with the proper desktop resolution(taken via EnumDisplaySettingsExA/ENUM_CURRENT_SETTINGS) before changing the state solved it.