如何获取DXGI中显示器/输出的当前显示模式(分辨率,刷新率)?

我正在创build一个多显示器全屏DXGI / D3D应用程序。 我正在通过可用的输出和适配器来准备创build交换链。

当使用DXGI的IDXGIFactory :: CreateSwapChain方法创build交换链时,我需要提供一个交换链描述,其中包含DXGI_MODE_DESCtypes的缓冲区描述,详细说明宽度,高度,刷新率等。我怎样才能知道输出是什么目前设置为(或者我怎么知道当前输出的显示模式是什么)? 当我使用此交换链全屏时,我不想更改用户的分辨率或刷新率。

Solutions Collecting From Web of "如何获取DXGI中显示器/输出的当前显示模式(分辨率,刷新率)?"

经过四处寻找,我偶然发现了EnumDisplaySettings传统的GDI函数,它允许我访问当前的分辨率和刷新率。 结合IDXGIOutput::FindClosestMatchingMode函数,我可以非常接近当前的显示模式:

 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(&current, outCurrentDisplayMode, NULL); } 

…但我不认为这是真正的答案,因为我需要使用遗留功能。 有没有办法做到这一点与DXGI得到确切的当前显示模式,而不是使用这种方法?

我在这里看到解决方案: http : //www.rastertek.com/dx11tut03.html

在以下部分:

  // Now go through all the display modes and find the one that matches the screen width and height. // When a match is found store the numerator and denominator of the refresh rate for that monitor. for(i=0; i<numModes; i++) { if(displayModeList[i].Width == (unsigned int)screenWidth) { if(displayModeList[i].Height == (unsigned int)screenHeight) { numerator = displayModeList[i].RefreshRate.Numerator; denominator = displayModeList[i].RefreshRate.Denominator; } } } 

我的理解是正确的,可用的分辨率是在displayModeList。

 This might be what you are looking for: // Get display mode list std::vector<DXGI_MODE_DESC*> modeList = GetDisplayModeList(*outputItor); for(std::vector<DXGI_MODE_DESC*>::iterator modeItor = modeList.begin(); modeItor != modeList.end(); ++modeItor) { // PrintDisplayModeInfo(*modeItor); } } std::vector<DXGI_MODE_DESC*> GetDisplayModeList(IDXGIOutput* output) { UINT num = 0; DXGI_FORMAT format = DXGI_FORMAT_R32G32B32A32_TYPELESS; UINT flags = DXGI_ENUM_MODES_INTERLACED | DXGI_ENUM_MODES_SCALING; // Get number of display modes output->GetDisplayModeList(format, flags, &num, 0); // Get display mode list DXGI_MODE_DESC * pDescs = new DXGI_MODE_DESC[num]; output->GetDisplayModeList(format, flags, &num, pDescs); std::vector<DXGI_MODE_DESC*> displayList; for(int i = 0; i < num; ++i) { displayList.push_back(&pDescs[i]); } return displayList; }