当前位置: 动力学知识库 > 问答 > 编程问答 >

winapi - Count monitors from a service with C++

问题描述:

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?

网友答案:

First, why is the console special to a service, vs number of displays attached on a remote session? Then, what about display mirroring / extended desktop / eyefinity?

Now, learn about Window Stations and Desktops. Then learn about shatter attacks.

Finally, if what you're really after is hardware enumeration, there are APIs for that. SetupDiGetClassDevs on the display monitor setup class will tell you how many physical screens the video card(s) expose.

分享给朋友:
您可能感兴趣的文章:
随机阅读: