多个显示器和手柄

时间:2014-10-11 08:08:10

标签: c++ resolution hdc monitors

尝试通过物理监视器运行for循环,但是句柄让我感到困惑,我的伪代码运行如下:

int tempCounter=0
for(counter = number of monitors;counter > 0;counter--){

    RECT tempRECT;
    HDC tempHDC;

    Get resolution of DC handle (counter) -> tempRECT;
    arrayList[tempCounter] = tempRECT;
    Get virtual work area of DC handle (counter) -> tempRECT;
    arrayList[tempCounter++] = tempRECT;
    tempCounter++;
}    

GetSystemMetrics(80)显示监视器的数量,这是否可靠使用,或者它可能失败的任何例外?

我知道那里没有多少,但是在MSDN上查看只是让我绕圈子,我并不是很有能力编程。

1 个答案:

答案 0 :(得分:2)

可以这么简单:

#include <Windows.h>
#include <stdio.h>

BOOL CALLBACK MonitorEnumProc(
    HMONITOR hMonitor,
    HDC hdcMonitor,
    LPRECT lprcMonitor,
    LPARAM dwData
    )
{
    printf("%dx%d\n", lprcMonitor->right, lprcMonitor->bottom);
}

int main(int argc, char*argv[]) {

    EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, 0);
}
相关问题