How do I get the dimensions (resolution) of each display?
#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;}
To enumerate all the devices attached to the computer, call the EnumDisplayDevices
function and enumerate the devices. Then call EnumDisplayMonitors
. This returns a handle to each monitor (HMONITOR
), which is used with GetMonitorInfo
.
You can also use WMI's Win32_DesktopMonitor
class, if the OS is Windows XP SP2 or higher (it fails under SP1).
Also you can try to use 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