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

标签 c++ windows graphics directx dxgi

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

Resolution

但是,程序将其报告为 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.

关于c++ - DXGI 显示器枚举未提供 Dell P2715Q 显示器的完整尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48172751/

相关文章:

objective-c - 在drawRect中向UIView添加渐变

c++ - 在类声明中使用 virtual 关键字

c++ - 将新创建的对象传递给函数时是否可以避免复制构造函数?

c# - 如何使用 webkit 浏览器引擎构建 web 浏览器 for windows

windows - 允许外部用户与内部服务通信

opengl - 为什么相机默认面向z轴负端?

java - 在正确的位置绘制多边形

C++:如何从 make_shared 部分推导模板参数

c++ - libcurl 在 ubuntu 虚拟机上完美运行,但无法解析 Windows 上的主机

windows - 我无法使用 TortoiseGit 推送本地修改