本文介绍了如何获取Windows中的显示数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算活动显示的数量。对于Mac我可以使用以下:

I want to count the number of active displays. For Mac I can use the following:

CGDisplayCount nDisplays;
CGGetActiveDisplayList(0,0, &nDisplays);
log.printf("Displays connected: %d",(int)nDisplays);

如何在Windows中实现相同的功能?我找到了,但我找到了

How can I achieve the same in Windows? I've found EnumDisplayMonitors but I can't work out how to use it.

推荐答案

正如您所发现的,会做这项工作,但它是一个有点棘手的调用。该文档声明:

As you have discovered, EnumDisplayMonitors() will do the job but it is a little tricky to call. The documentation states:

这使我们更容易的解决方案:。事实上,如果你有psuedo监视器,这可能比 EnumDisplayMonitors()更好。

This leads us to an easier solution: GetSystemMetrics(SM_CMONITORS). Indeed this may be even better than EnumDisplayMonitors() if you have psuedo-monitors.

如下调用 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
}

这篇关于如何获取Windows中的显示数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 16:26