How to get the size (resolution) of each display?

I need help extracting the resolutions of my screens, as shown in the image below.

one 1680x1050, another 1366x768, and a third 1280x800

I found this documentation and it was really useful. Here is the code I tried based on these 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 to get information about other monitors?

+6
source share
2 answers
 #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; } 
+4
source

To list all devices connected to the computer, call the EnumDisplayDevices function and list the devices. Then call EnumDisplayMonitors . This returns a handle to each monitor ( HMONITOR ) that is used with GetMonitorInfo .

You can also use the WMI Win32_DesktopMonitor class if the OS is Windows XP Service Pack 2 (SP2) or higher (it does not work under SP1).

You can also try using the EDID values ​​from the registry to get the size, but in many cases the EDID value is not valid.

Registry path

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Enum \ DISPLAY

+2
source

All Articles