Microsoft KB Archive/197671

= HOWTO: How to Enumerate Monitors in Win 98 and Windows 2000 =

Article ID: 197671

Article Last Modified on 2/27/2007

-

APPLIES TO


 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Professional Edition
 * Microsoft Windows 98 Standard Edition

-



This article was previously published under Q197671



SUMMARY
Starting with Microsoft Windows 98 and Microsoft Windows 2000, multiple monitors could be attached to a computer and connected to the desktop. This article contains sample code showing how to enumerate those devices attached to the desktop.



MORE INFORMATION
The following code is for a small console-mode application that enumerates the attached display devices:

Sample Code
#include   #include    #ifndef SM_CMONITORS

typedef HANDLE HMONITOR;

#endif #ifndef DISPLAY_DEVICE_PRIMARY_DEVICE

typedef struct _DISPLAY_DEVICE { DWORD cb; TCHAR DeviceName[32]; TCHAR DeviceString[128]; DWORD StateFlags; } DISPLAY_DEVICE, *PDISPLAY_DEVICE, *LPDISPLAY_DEVICE; #define DISPLAY_DEVICE_ATTACHED_TO_DESKTOP 0x00000001 #define DISPLAY_DEVICE_MULTI_DRIVER       0x00000002 #define DISPLAY_DEVICE_PRIMARY_DEVICE     0x00000004 #define DISPLAY_DEVICE_VGA            0x00000010

#endif

main (int argc, char**argv) {

int i;  int j=0; BOOL (WINAPI* pEnumDisplayDevices)(PVOID,DWORD,PVOID,DWORD);

(FARPROC)pEnumDisplayDevices = GetProcAddress(       LoadLibrary("USER32"), "EnumDisplayDevicesA");

if (pEnumDisplayDevices) {       DISPLAY_DEVICE dd; ZeroMemory(&dd, sizeof(dd)); dd.cb = sizeof(dd);

printf("*** EnumDisplayDevices\n");

for (i=0; (*pEnumDisplayDevices)(NULL, i, &dd, 0); i++) {        j++; printf("   DeviceName:   '%s'\n", dd.DeviceName); printf("   DeviceString: '%s'\n", dd.DeviceString); printf("   Flags:        %08X %s%s\n",                dd.StateFlags,                ((dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) ? "Desktop " : ""),

((dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) ? "Primary

" : ""));

}      }

return j;  }

