
Recently I was busy with the normal initialization of the window, and the task was to detect all monitors and their resolutions. I leave here a solution for posterity.
appRet aApplication::ObtainMonitors() { DWORD i = 0; DWORD j; DISPLAY_DEVICE dc; dc.cb = sizeof(dc); while(EnumDisplayDevices(NULL, i, &dc, EDD_GET_DEVICE_INTERFACE_NAME) != 0) { if ((dc.StateFlags & DISPLAY_DEVICE_ACTIVE) && !(dc.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)) { DEVMODE dm; j = 0; while(EnumDisplaySettings(dc.DeviceName, j, &dm) != 0) {
Because we do not know in advance what devices can be in the system, then we will have to run in cycles. First, through the second parameter of the
EnumDisplayDevices function
, we
iterate through all the monitors in the current user session. Then after
if (dc.StateFlags & DISPLAY_DEVICE_ACTIVE) we are convinced that the “monitor” is in touch and not sleeping. Well, after we learn his name in
dc.DeviceName and can run through
EnumDisplaySettings on all available permissions of this “monitor”.
I tested it by connecting LG to a laptop: canal, detecting and even using it.
UPD : Added a conditional check on the parameter
DISPLAY_DEVICE_MIRRORING_DRIVER to discard the virt. devices. Thank you
shrikus