How to get current display mode (resolution, refresh rate) of a monitor/output in DXGI?

后端 未结 3 1020
野性不改
野性不改 2021-02-13 13:24

I am creating a multi-monitor full screen DXGI/D3D application. I am enumerating through the available outputs and adapters in preparation of creating their swap chains.

3条回答
  •  余生分开走
    2021-02-13 13:40

    After looking around some more I stumbled upon the EnumDisplaySettings legacy GDI function, which allows me to access the current resolution and refresh rate. Combining this with the IDXGIOutput::FindClosestMatchingMode function I can get pretty close to the current display mode:

    void getClosestDisplayModeToCurrent(IDXGIOutput* output, DXGI_MODE_DESC* outCurrentDisplayMode)
    {
      DXGI_OUTPUT_DESC outputDesc;
      output->GetDesc(&outputDesc);
      HMONITOR hMonitor = outputDesc.Monitor;
      MONITORINFOEX monitorInfo;
      monitorInfo.cbSize = sizeof(MONITORINFOEX);
      GetMonitorInfo(hMonitor, &monitorInfo);
      DEVMODE devMode;
      devMode.dmSize = sizeof(DEVMODE);
      devMode.dmDriverExtra = 0;
      EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
    
      DXGI_MODE_DESC current;
      current.Width = devMode.dmPelsWidth;
      current.Height = devMode.dmPelsHeight;
      bool useDefaultRefreshRate = 1 == devMode.dmDisplayFrequency || 0 == devMode.dmDisplayFrequency;
      current.RefreshRate.Numerator = useDefaultRefreshRate ? 0 : devMode.dmDisplayFrequency;
      current.RefreshRate.Denominator = useDefaultRefreshRate ? 0 : 1;
      current.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
      current.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
      current.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
    
      output->FindClosestMatchingMode(¤t, outCurrentDisplayMode, NULL);
    }
    

    ...But I don't think that this is really the correct answer because I'm needing to use legacy functions. Is there any way to do this with DXGI to get the exact current display mode rather than using this method?

提交回复
热议问题