#include <Windows.h>
#include <vector>
#include <iostream>
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData);
int main()
{
// 枚举每个显示器
std::vector<MONITORINFOEX> monitors;
EnumDisplayMonitors(nullptr, nullptr, MonitorEnumProc, reinterpret_cast<LPARAM>(&monitors));
// 输出每个显示器的分辨率和起点信息
for (int i = 0; i < monitors.size(); i++)
{
std::cout << "Screen " << i << " Resolution: " << monitors[i].rcMonitor.right - monitors[i].rcMonitor.left << "x" << monitors[i].rcMonitor.bottom - monitors[i].rcMonitor.top << std::endl;
std::cout << "Screen " << i << " Origin: (" << monitors[i].rcMonitor.left << ", " << monitors[i].rcMonitor.top << ")" << std::endl;
}
system("pause");
return 0;
}
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
std::vector<MONITORINFOEX>* pMonitors = reinterpret_cast<std::vector<MONITORINFOEX>*>(dwData);
MONITORINFOEX monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(hMonitor, &monitorInfo);
pMonitors->push_back(monitorInfo);
return TRUE;
}
07-15
1273
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-21
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交