Because display hardware varies, not all devices will support all display modes. To determine the display modes supported on a given system, call the IDirectDraw2::EnumDisplayModes method. By setting the appropriate values and flags, the IDirectDraw2::EnumDisplayModes method can list all supported display modes or confirm that a single display mode that you specify is supported. The method's first parameter, dwFlags, controls extra options for the method; in most cases, you will set dwFlags to 0 to ignore extra options. The second parameter, lpDDSurfaceDesc, is the address of a DDSURFACEDESC structure that describes a given display mode to be confirmed; you'll usually set this parameter to NULL to request that all modes be listed. The third parameter, lpContext, is a pointer that you want DirectDraw to pass to your callback function; if you don't need any extra data in the callback function, use NULL here. Last, you set the lpEnumModesCallback parameter to the address of the callback function that DirectDraw will call for each supported mode.
The callback function you supply when calling IDirectDraw2::EnumDisplayModes must match the prototype for the EnumModesCallback function. For each display mode that the hardware supports, DirectDraw calls your callback function passing two parameters. The first parameter is the address of a DDSURFACEDESC structure that describes one supported display mode, and the second parameter is the address of the application-defined data you specified when calling IDirectDraw2::EnumDisplayModes, if any.
Examine the values in the DDSURFACEDESC structure to determine the display mode it describes. The key structure members are the dwWidth, dwHeight, and ddpfPixelFormat members. The dwWidth and dwHeight members describe the display mode's dimensions, and the ddpfPixelFormat member is a DDPIXELFORMAT structure that contains information about the mode's bit depth.
The DDPIXELFORMAT structure carries information describing the mode's bit depth and tells you whether or not the display mode uses a palette. If the dwFlags member contains the DDPF_PALETTEINDEXED1, DDPF_PALETTEINDEXED2, DDPF_PALETTEINDEXED4, or DDPF_PALETTEINDEXED8 flag, the display mode's bit depth is 1, 2, 4 or 8 bits, and each pixel is an index into an associated palette. If dwFlags contains DDPF_RGB, then the display mode is non-palettized and its bit depth is provided in the dwRGBBitCount member of the DDPIXELFORMAT structure.