DirectX SDK

Determining Supported Display Modes

[C++]

Because display hardware varies, not all devices will support all display modes. To determine the display modes supported on a given system, call the IDirectDraw7::EnumDisplayModes method. By setting the appropriate values and flags, the 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 DDSURFACEDESC2 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 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 DDSURFACEDESC2 structure that describes one supported display mode, and the second parameter is the address of the application-defined data you specified when calling EnumDisplayModes, if any.

Examine the values in the DDSURFACEDESC2 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.

[Visual Basic]

Because display hardware varies, not all devices will support all display modes. To determine the display modes supported on a given system, call the DirectDraw7.GetDisplayModesEnum method. The method returns a DirectDrawEnumModes object which is then used to retrieve descriptions of the supported display modes. By setting the appropriate values and flags, the GetDisplayModesEnum method fills the DirectDrawEnumModes object with the a list of all supported display modes or confirm that a single display mode that you specify is supported. The method's first parameter, flags, controls extra options for the method; in most cases, you will set flags to DDEDM_DEFAULT to ignore extra options. The second parameter, ddsd, is a DDSURFACEDESC2 type that describes a given display mode to be confirmed; you'll usually set this parameter to Nothing to request that all modes be listed.

After the DirectDrawEnumModes object is returned from the GetDisplayModesEnum method you can call the DirectDrawEnumModes.GetCount method to find out how many supported display modes are available. You then call DirectDrawEnumModes.GetItem to return a description of a single display mode from the collection of display modes in the DirectDrawEnumModes object.

Examine the values in the DDSURFACEDESC2 type retrieved from the GetItem method to determine the display mode it describes. The key type members are the lWidth, lHeight, and ddpfPixelFormat members. The lWidth and lHeight members describe the display mode's dimensions, and the ddpfPixelFormat member is a DDPIXELFORMAT type that contains information about the mode's bit depth.

The DDPIXELFORMAT type carries information describing the mode's bit depth and tells you whether or not the display mode uses a palette. If the lFlags 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 lFlags contains DDPF_RGB, then the display mode is non-palettized and its bit depth is provided in the lRGBBitCount member of the DDPIXELFORMAT type.