如何获得Win32 API中所有屏幕的尺寸(RECT)? [英] How do I get the dimensions (RECT) of all the screens in win32 API?

查看:895
本文介绍了如何获得Win32 API中所有屏幕的尺寸(RECT)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为测试团队编写一个应用程序.该应用程序的作用是使您可以截取屏幕任何部分的屏幕截图(然后将其上传到带有注释的测试团队服务器中).

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 team server with comments).

获取屏幕快照涉及选择屏幕上的区域以进​​行屏幕快照.为此,我创建了一个半透明的窗口并将其覆盖在整个屏幕上.我目前正在使用GetDesktopWindow()GetWindowRect()来获取屏幕尺寸,但这在多屏幕环境中不起作用.

Taking screenshot involves selecting the region on the screen to take screenshot of. For this I'm creating a semi-transparent window and overlaying it over the entire screen. I'm currently using GetDesktopWindow() and GetWindowRect() to get the dimensions of the screen but this doesn't work in multi-screen environments.

如何在所有可能的屏幕上覆盖一个窗口?

How do I overlay a window over all possible screens?

屏幕配置可能非常奇怪,例如:

The screen configurations can be pretty exotic, such as:

     [LCD]
[LCD][LCD][LCD]

(4个LCD屏幕-顶部一个,底部3个)

(4 lcd screens - one at the top, 3 at the bottom)

[LCD]     [LCD]
[LCD][LCD][LCD]
[LCD]     [LCD]

(7个LCD屏幕-右侧3个,左侧3个,中间1个).

(7 lcd screens - 3 on the right, 3 on the left, 1 in the middle).

等等.

有人知道我如何在所有屏幕上覆盖1个窗口吗?我不知道第一个异国情调的示例中的尺寸会是什么样子,而左右行的顶部都没有屏幕?

Does anyone know how I could overlay 1 window all the screens? I wonder what the dimensions would look like in the 1st exotic example, when there is no screen on the top-row left and right?

也许我应该为每个LCD屏幕创建一个覆盖窗口?

Perhaps I should be creating one overlay window per LCD screen?

有什么想法吗?

推荐答案

您可以为此使用EnumDisplayMonitors函数.这是一个小类,它会自动为系统中所有监视器以及所有监视器的并集建立一个向量.

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<RECT>   rcMonitors;
    RECT                rcCombined;

    static BOOL CALLBACK MonitorEnum(HMONITOR hMon,HDC hdc,LPRECT lprcMonitor,LPARAM pData)
    {
        MonitorRects* pThis = reinterpret_cast<MonitorRects*>(pData);
        pThis->rcMonitors.push_back(*lprcMonitor);
        UnionRect(&pThis->rcCombined, &pThis->rcCombined, lprcMonitor);
        return TRUE;
    }

    MonitorRects()
    {
        SetRectEmpty(&rcCombined);
        EnumDisplayMonitors(0, 0, MonitorEnum, (LPARAM)this);
    }
};

如果仅使用rcCombined矩形创建一个大窗口,它将覆盖所有屏幕,系统将自动裁剪掉缺失"位.

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.

这篇关于如何获得Win32 API中所有屏幕的尺寸(RECT)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆