2014-10-11 56 views
-1

试图通过物理监视器循环运行,但手柄真的困惑我,我有沿着线运行的伪代码:多显示器和手柄

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上看着我只是围绕着圈子,而且我不是很擅长编程。

+2

你实际的代码是假想错误,伪码不显示的问题。 ['EnumDisplayMonitors'](http://msdn.microsoft.com/en-us/library/dd162610)是你如何枚举监视器(没有计数器)。 – 2014-10-11 09:13:53

+0

我知道我需要使用EnumDisplayMonitors,但这不仅让我困惑。 MSDN对我如何做我想做的事情感到困惑。我不知道如何获得不同显示器的处理。 – 2014-10-11 09:20:32

+1

您可以调用'EnumDisplayMonitors'并传递您的函数,并为您调用并接收监视器句柄作为参数。此外,[此代码片段显示使用情况](http://alax.info/trac/public/browser/trunk/Utilities/MonitorInformation/MainDialog.h#L127)。 – 2014-10-11 09:23:34

回答

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); 
}