DXGI 显示器枚举未提供 Dell P2715Q 显示器的完整尺寸

DXGI monitors enumeration does not give full size for Dell P2715Q monitor

我制作 DXGI 适配器和监视器枚举。我电脑连接的第二台显示器是Dell P2715Q,分辨率为3840*2160:

但是,程序将其报告为 2560*1440,这是第二个可用分辨率。最少的重现代码:

int main()
{
IDXGIFactory1* pFactory1;

HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&pFactory1));

if (FAILED(hr))
{
    wcout << L"CreateDXGIFactory1 failed. " << endl;
    return 0;
}

for (UINT i = 0;; i++)
{
    IDXGIAdapter1* pAdapter1 = nullptr;

    hr = pFactory1->EnumAdapters1(i, &pAdapter1);

    if (hr == DXGI_ERROR_NOT_FOUND)
    {
        // no more adapters
        break;
    }

    if (FAILED(hr))
    {
        wcout << L"EnumAdapters1 failed. " << endl;
        return 0;
    }

    DXGI_ADAPTER_DESC1 desc;

    hr = pAdapter1->GetDesc1(&desc);

    if (FAILED(hr))
    {
        wcout << L"GetDesc1 failed. " << endl;
        return 0;
    }

    wcout << L"Adapter: " << desc.Description << endl;

    for (UINT j = 0;; j++)
    {
        IDXGIOutput *pOutput = nullptr;

        HRESULT hr = pAdapter1->EnumOutputs(j, &pOutput);

        if (hr == DXGI_ERROR_NOT_FOUND)
        {
            // no more outputs
            break;
        }

        if (FAILED(hr))
        {
            wcout << L"EnumOutputs failed. " << endl;
            return 0;
        }

        DXGI_OUTPUT_DESC desc;

        hr = pOutput->GetDesc(&desc);

        if (FAILED(hr))
        {
            wcout << L"GetDesc1 failed. " << endl;
            return 0;
        }

        wcout << L"  Output: " << desc.DeviceName <<
            L"  (" << desc.DesktopCoordinates.left << L"," << desc.DesktopCoordinates.top << L")-(" <<
            (desc.DesktopCoordinates.right - desc.DesktopCoordinates.left) << L"," << 
            (desc.DesktopCoordinates.bottom - desc.DesktopCoordinates.top) << L")" << endl;

    }
}

return 0;
}

输出:

Adapter: Intel(R) Iris(TM) Pro Graphics 6200
   Output: \.\DISPLAY1  (0,0)-(1920,1200)
   Output: \.\DISPLAY2  (1920,0)-(2560,1440)

什么会导致此行为:DirectX 限制、视频内存、显示适配器、驱动程序、显示器?

环境:

Windows 10 x64
Intel(R) Iris(TM) Pro Graphics 6200
DELL P2715Q

您的应用程序被视为不了解 DPI 缩放。操作系统为您缩放坐标,大概是为了保持与遗留应用程序的兼容性。

让系统知道你知道High DPI Desktop Application Development,你会得到你期望的坐标:

#include <ShellScalingAPI.h>

#pragma comment(lib, "shcore.lib")

int main()
{
    SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE);
    // there goes your code
Adapter: Intel(R) HD Graphics 4600
  Output: \.\DISPLAY4  (0,0)-(3840,2160)
  Output: \.\DISPLAY5  (3840,0)-(3840,2160)

没有SetProcessDpiAwareness:

Adapter: Intel(R) HD Graphics 4600
  Output: \.\DISPLAY4  (0,0)-(2194,1234)
  Output: \.\DISPLAY5  (2194,0)-(2194,1234)

注意 DXGI_OUTPUT_DESC structure 对 MSDN 的评论:

DesktopCoordinates

Type: RECT

A RECT structure containing the bounds of the output in desktop coordinates. Desktop coordinates depend on the dots per inch (DPI) of the desktop. For info about writing DPI-aware Win32 apps, see High DPI.

作为 Roman answer 的替代方法,您可以将清单添加到您的项目以使其具有 dpi 感知能力。

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
  <asmv3:application>
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>true</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>
</assembly>