簡體   English   中英

如何獲得每個顯示器的尺寸(分辨率)?

[英]How do I get the dimensions (resolution) of each display?

我需要有關如何檢索屏幕分辨率的幫助,如下圖所示。

一個1680x1050,另一個1366x768,第三個1280x800

我找到了這個文檔 ,它真的很有幫助。 這是我嘗試的代碼,基於這些文檔:

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";

但是,它僅識別並提供有關監視器的信息。 我如何獲得有關其他顯示器的信息?

#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;
}

要枚舉連接到計算機的所有設備,請調用EnumDisplayDevices函數並枚舉設備。 然后調用EnumDisplayMonitors 這將返回每個監視器( HMONITOR )的句柄,該句柄與GetMonitorInfo一起GetMonitorInfo

如果操作系統是Windows XP SP2或更高版本(在SP1下失敗),您也可以使用WMI的Win32_DesktopMonitor

此外,您可以嘗試使用注冊表中的EDID值來獲取大小,但在許多情況下,EDID值無效。

注冊表路徑

HKEY_LOCAL_MACHINE \\系統\\ CurrentControlSet \\枚舉\\ DISPLAY

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM