How do I get the dimensions (RECT) of all the screens in win32 API?

前端 未结 3 579
北海茫月
北海茫月 2021-01-13 06:06

I\'m writing an application for the testing team. What this application does is it lets you take a screenshot of any part of the screen (and then it uploads it to testing te

3条回答
  •  执念已碎
    2021-01-13 06:38

    You can use the EnumDisplayMonitors function for this. Here's a little class that automatically builds a vector of all monitors in the system, as well as a union of them all.

    struct MonitorRects
    {
        std::vector   rcMonitors;
        RECT                rcCombined;
    
        static BOOL CALLBACK MonitorEnum(HMONITOR hMon,HDC hdc,LPRECT lprcMonitor,LPARAM pData)
        {
            MonitorRects* pThis = reinterpret_cast(pData);
            pThis->rcMonitors.push_back(*lprcMonitor);
            UnionRect(&pThis->rcCombined, &pThis->rcCombined, lprcMonitor);
            return TRUE;
        }
    
        MonitorRects()
        {
            SetRectEmpty(&rcCombined);
            EnumDisplayMonitors(0, 0, MonitorEnum, (LPARAM)this);
        }
    };
    

    If you just create one big window using the rcCombined rectangle from that, it will overlay all the screens and the "missing" bits will just be clipped out automatically by the system.

提交回复
热议问题