我想计算事件显示器的数量。对于 Mac,我可以使用以下内容:
CGDisplayCount nDisplays;
CGGetActiveDisplayList(0,0, &nDisplays);
log.printf("Displays connected: %d",(int)nDisplays);
如何在 Windows 中实现相同的目的?我找到了 EnumDisplayMonitors但我不知道如何使用它。
最佳答案
如您所见,EnumDisplayMonitors()
会完成这项工作,但打电话有点棘手。文档指出:
The EnumDisplayMonitors function enumerates display monitors (including invisible pseudo-monitors associated with the mirroring drivers) that intersect a region formed by the intersection of a specified clipping rectangle and the visible region of a device context. EnumDisplayMonitors calls an application-defined MonitorEnumProc callback function once for each monitor that is enumerated. Note that GetSystemMetrics (SM_CMONITORS) counts only the display monitors.
这使我们找到了一个更简单的解决方案:GetSystemMetrics(SM_CMONITORS)
.事实上,如果您有伪监视器,这可能比 EnumDisplayMonitors()
更好。
作为调用 EnumDisplayMonitors()
的示例,试试这个:
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
int *Count = (int*)dwData;
(*Count)++;
return TRUE;
}
int MonitorCount()
{
int Count = 0;
if (EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, (LPARAM)&Count))
return Count;
return -1;//signals an error
}
关于c++ - 如何获取窗口中的显示数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7767036/