有没有办法在c ++和winapi中获得推荐的分辨率?
使用GetMonitorInfo
,EnumDisplaySettings
,EnumDisplayMonitors
或GetSystemMetrics
仅获得当前分辨率。
编辑: 经过一番研究,我找到了示例代码Example code for displaying an app on a portrait device。
即使与原始分辨率无关,它也会显示如何获取分辨率。为此,请看一下函数HRESULT GetPathInfo(_In_ PCWSTR pszDeviceName, _Out_ DISPLAYCONFIG_PATH_INFO* pPathInfo)
和bool IsNativeOrientationPortrait(const LUID AdapterLuid, const UINT32 TargetId)
。
到目前为止,该代码仍然有效,但是我不知道在Windows 8.1和早期版本中该代码的行为。尚未进行任何进一步的测试。
答案 0 :(得分:0)
实际上,您可以执行GetSupportedFullScreenResolutions以获得显示器支持的分辨率列表,通常最后一个索引是显示器的最佳(最高)分辨率。
赞:
#include <Windows.h>
#include <iostream>
using namespace std;
int main()
{
DEVMODE dm = { 0 };
dm.dmSize = sizeof(dm);
for (int iModeNum = 0; EnumDisplaySettings(NULL, iModeNum, &dm) != 0; iModeNum++)
{
cout << "Mode #" << iModeNum << " = " << dm.dmPelsWidth << "x" << dm.dmPelsHeight << endl;
}
return 0;
}
编辑:
您可以获取图形卡的分辨率,并将获得的最大分辨率与屏幕分辨率进行比较。通常,两者中最小的是最佳分辨率。
#include <Windows.h>
#include <iostream>
using namespace std;
int main()
{
UINT32 PathArraySize = 0;
UINT32 ModeArraySize = 0;
DISPLAYCONFIG_PATH_INFO* PathArray;
DISPLAYCONFIG_MODE_INFO* ModeArray;
DISPLAYCONFIG_TOPOLOGY_ID CurrentTopology;
//Directly query the resolution of the graphics card and get the physical resolution all the time.
GetDisplayConfigBufferSizes(QDC_ALL_PATHS, &PathArraySize, &ModeArraySize);
PathArray = (DISPLAYCONFIG_PATH_INFO*)malloc(PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));
memset(PathArray, 0, PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));
ModeArray = (DISPLAYCONFIG_MODE_INFO*)malloc(ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));
memset(ModeArray, 0, ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));
LONG ret = QueryDisplayConfig(QDC_DATABASE_CURRENT, &PathArraySize, PathArray, &ModeArraySize, ModeArray, &CurrentTopology);
int x_DisplayConfigScreen = ModeArray->targetMode.targetVideoSignalInfo.activeSize.cx;
int y_DisplayConfigScreen = ModeArray->targetMode.targetVideoSignalInfo.activeSize.cy;
return 0;
}