EnumDisplayDevices

The EnumDisplayDevices function lets you obtain information about the display devices in a system.

BOOL EnumDisplayDevices(
  PVOID Unused,       // not used; must be NULL
  DWORD iDevNum,      // specifies display device
  PDISPLAY_DEVICE lpDisplayDevice,  // pointer to structure to
                      // receive display device information
  DWORD dwFlags       // flags to condition function behavior
);
 

Parameters

Unused
This parameter is currently not used. Set it to NULL.
iDevNum
Index value that specifies the display device of interest.

The operating system identifies each display device with an index value. The index values are consecutive integers, starting at 0. If a system has three display devices, for example, they are specified by the index values 0, 1, and 2.

lpDisplayDevice
Pointer to a DISPLAY_DEVICE structure that receives information about the display device specified by iDevNum.

Before calling EnumDisplayDevices, you must initialize the cb member of DISPLAY_DEVICE to the size, in bytes, of DISPLAY_DEVICE.

dwFlags
A set of flags that condition the behavior of the function.

There are no flags currently defined.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. The function fails if iDevNum is greater than the largest device index.

Remarks

In order to query all display devices in the system, call this function in a loop, starting with iDevNum set to 0, and incrementing iDevNum until the function fails.

Code Examples

To paint in response to a WM_PAINT message, using the capabilities of each monitor, you can use code like the following in a window procedure:

case WM_PAINT:
    hdc = BeginPaint(hwnd, &ps);
    EnumDisplayMonitors(hdc, NULL, MyPaintEnumProc, 0);
    EndPaint(hwnd, &ps);
 

To paint the upper half of a window using the capabilities of each monitor, you can use code like the following:

GetClientRect(hwnd, &rc);
rc.bottom = (rc.bottom - rc.top) / 2;
hdc = GetDC(hwnd);
EnumDisplayMonitors(hdc, &rc, MyPaintEnumProc, 0);
ReleaseDC(hwnd, hdc);
 

To paint the entire screen optimally for each display monitor, you can use code like the following:

hdc = GetDC(NULL);
EnumDisplayMonitors(hdc, NULL, MyPaintScreenEnumProc, 0);
ReleaseDC(NULL, hdc);
 

To get information about all the display monitors, you can use code like the following:

EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, 0);
 

QuickInfo

  Windows NT: Requires version 5.0 or later.
  Windows: Unsupported.
  Windows CE: Unsupported.
  Header: Declared in winuser.h.
  Import Library: Use user32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also

Device Contexts Overview, Device Context Functions, ChangeDisplaySettings, ChangeDisplaySettingsEx, CreateDC, DEVMODE, DISPLAY_DEVICE, EnumDisplaySettings