I'm trying to count the number of monitors (i.e. screens) attached to the console from a service application. I do the following:
int CountMonitors()
{
int nCnt = 0;
if(!EnumDisplayMonitors(NULL, NULL, _countMonitorEnumProc, (LPARAM)&nCnt))
{
//Error
nCnt = -1;
}
return nCnt;
}
BOOL _countMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
int* pCnt = (int*)dwData;
(*pCnt)++;
return TRUE;
}
but the count is always 1 (when I'm testing it on a dual-monitor Windows 7.) I then do this (which is not exactly what I need due to its limitation):
int nCnt = GetSystemMetrics(SM_CMONITORS);
and the result is also 1.
So how do you count monitors from a service?