C++ DXGI监视器枚举未给出Dell P2715Q监视器的完整大小

C++ DXGI监视器枚举未给出Dell P2715Q监视器的完整大小,c++,windows,graphics,directx,dxgi,C++,Windows,Graphics,Directx,Dxgi,我制作DXGI适配器和监视器枚举。连接到我的计算机的第二台显示器是Dell P2715Q,分辨率为3840*2160: 然而,该程序将其报告为2560*1440,这是第二个可用的分辨率。要复制的最小代码: int main() { IDXGIFactory1* pFactory1; HRESULT hr = CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&pFactory1)); if (FAILED(hr)) {

我制作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;
}
intmain()
{
IDXGIFactory1*PFFactory1;
HRESULT hr=CreateDXGIFactory1(uu uuidof(IDXGIFactory1),(void**)(&pFactory1));
如果(失败(小时))
{

wcout您的应用程序被视为不知道DPI缩放。操作系统会为您缩放坐标,以保持与遗留应用程序的兼容性

让系统知道您知道,您将获得预期的坐标:

#include <ShellScalingAPI.h>

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

int main()
{
    SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE);
    // there goes your code
setProcessdPiaware

适配器:英特尔(R)高清图形4600
输出:\\.\DISPLAY4(0,0)-(21941234)
输出:\\.\DISPLAY5(2194,0)-(21941234)
关于MSDN的注释和评论:

桌面坐标

类型:RECT

包含以桌面坐标表示的输出边界的RECT结构。桌面坐标取决于桌面的每英寸点数(DPI)。有关编写支持DPI的Win32应用程序的信息,请参阅高DPI


作为Roman答案的替代方案,您可以向项目中添加清单,使其具有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>

真的

也许这不是第二分辨率,而是高DPIscaling@RomanR.您能再解释一下吗?谢谢。测试。同时,SetProcessDpiAwareness返回S_OK,但结果是相同的。SetProcessDpiAwareness(进程/监视器\u DPI感知)在我的电脑上做了这个把戏。在另一个程序中,这没有帮助,但在Windows显示设置中将文本大小设置为100%解决了问题。我需要进一步研究这个问题。感谢您指出了正确的方向。
PROCESS\u PER\u MONITOR\u DPI\u AWARE
当然是最灵活的。我想您首先使用的是每系统DPI(main)监视器DPI应用于所有监视器。无论哪种方式,它都是关于高DPI扩展的,并且可能很棘手(MSDN关于这方面的文章相当长,我对
SetProcessDpiAwareness
的引用只是一个粗略的示例,您已经了解了…)。
#include <ShellScalingAPI.h>

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

int main()
{
    SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE);
    // there goes your code
<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>