简体   繁体   English

使用C ++从服务计数监视器

[英]Count monitors from a service with C++

I'm trying to count the number of monitors (ie 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 ): 但是计数始终为1(当我在双显示器Windows 7上对其进行测试时),然后我执行此操作(由于其限制 ,这并不是我真正需要的):

int nCnt = GetSystemMetrics(SM_CMONITORS);

and the result is also 1. 结果也是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 . 现在,了解Window Stations和Desktops Then learn about shatter attacks. 然后了解粉碎攻击。

Finally, if what you're really after is hardware enumeration, there are APIs for that. 最后,如果您真正想要的是硬件枚举,则可以使用API​​。 SetupDiGetClassDevs on the display monitor setup class will tell you how many physical screens the video card(s) expose. 显示监视器安装程序类上的SetupDiGetClassDevs将告诉您视频卡可以显示多少个物理屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM