How do I enumerate all monitors in Windows 7?

Posted by Jon Tackabury on Stack Overflow See other posts from Stack Overflow or by Jon Tackabury
Published on 2010-04-12T16:11:11Z Indexed on 2010/04/12 16:13 UTC
Read the original article Hit count: 458

Filed under:
|
|

I am trying to enumerate all the monitors in Windows 7, and according to MSDN, using the QueryDisplayConfig method is the correct way to do this. All of this code works fine, and returns a couple of arrays, one with paths and one with modes. However, it doesn't have the same monitor ID's as Windows. I am trying to build an array of all the monitors that appear in the Windows 7 "Screen Resolution" dialog. The paths collection return far too many items, and I'm not sure how to tell if it's a valid non-active monitor. Any help would be much appreciated.

UINT32 PathArraySize = 0;
UINT32 ModeArraySize = 0;
DISPLAYCONFIG_PATH_INFO* PathArray;
DISPLAYCONFIG_MODE_INFO* ModeArray;

GetDisplayConfigBufferSizes(
    QDC_ALL_PATHS, &PathArraySize, &ModeArraySize);
PathArray = (DISPLAYCONFIG_PATH_INFO*)malloc(
    PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));
memset(PathArray, 0, PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));

ModeArray = (DISPLAYCONFIG_MODE_INFO*)malloc(
    ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));
memset(ModeArray, 0, ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));

LONG rtn = QueryDisplayConfig(
    QDC_ALL_PATHS, &PathArraySize, PathArray, &ModeArraySize, ModeArray, NULL);

alt text

© Stack Overflow or respective owner

Related posts about Windows

Related posts about c++