作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我制作 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 x64Intel(R) Iris(TM) Pro Graphics 6200DELL 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/
我是一名优秀的程序员,十分优秀!