如何获得每个显示器的尺寸(分辨率)? [英] How do I get the dimensions (resolution) of each display?

查看:735
本文介绍了如何获得每个显示器的尺寸(分辨率)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要如何检索屏幕分辨率的帮助,如下图所示。

I need help on how to retrieve the resolutions of my screens, as shown in the image below.

我发现本文档,它是真的有帮助。下面是我尝试的代码,基于这些文档:

I found this documentation and it was really helpful. Here's the code that I tried, based on those docs:

int numberOfScreens = GetSystemMetrics(SM_CMONITORS);
int width           = GetSystemMetrics(SM_CXSCREEN);
int height          = GetSystemMetrics(SM_CYSCREEN);

std::cout << "Number of monitors: " << numberOfScreens << "\n";  // returns 3
std::cout << "Width:"               << width           << "\n";
std::cout << "Height:"              << height          << "\n";

但是,它只能识别并提供有关如何获取有关其他显示器的信息?

However, it only identifies and gives information about the main monitor. How do I get information about the other monitors?

推荐答案

#include <Windows.h>

BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor,
                              HDC      hdcMonitor,
                              LPRECT   lprcMonitor,
                              LPARAM   dwData)
{
    MONITORINFO info;
    info.cbSize = sizeof(info);
    if (GetMonitorInfo(hMonitor, &info))
    {
        std::cout << "Monitor x: "<< std::abs(info.rcMonitor.left - info.rcMonitor.right)
                  <<" y: "        << std::abs(info.rcMonitor.top  - info.rcMonitor.bottom)
                  << std::endl;
    }
    return TRUE;  // continue enumerating
}

int main()
{
    EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, 0);

    return 0;
}

这篇关于如何获得每个显示器的尺寸(分辨率)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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