Enumerating the Display Modes

[Previous] [Next]

The next step in the DriverEnumCallback routine, labeled STEP 4, is to enumerate the available display modes on the current DirectDraw device. DirectDraw supports capabilities such as palette register handling (setting palette information) and blitting (copying 2D graphic data) automatically, so you don't need to handle each hardware type independently. However, you should be sure to use IDirectDraw7::EnumDisplayModes, as is done in the DriverEnumCallback routine, to determine what display modes the currently installed monitor supports. A display mode is a combination of pixel resolution (for example, 1024 × 768), pixel color depth (for example, 32-bit color), and refresh rate (for example, 85 Hz). DirectDraw will compare the monitor's capabilities with the available display modes, and if the monitor doesn't support the desired mode, IDirectDraw7::SetDisplayMode will fail. By determining the monitor's abilities through enumeration, you won't have to worry about the call failing because you'll know ahead of time what modes are available.

The IDirectDraw7::EnumDisplayModes method is declared as follows:

 HRESULT EnumDisplayModes(     DWORD dwFlags,     LPDDSURFACEDESC2 lpDDSurfaceDesc2,     LPVOID lpContext,     LPDDENUMMODESCALLBACK2 lpEnumModesCallback ); 

ParameterDescription
dwFlagsOne of the following flags:

DDEDM_REFRESHRATES   Enumerates the modes with different refresh rates. IDirectDraw7::EnumDisplayModes guarantees that a particular mode will be enumerated only once. This flag indicates whether the refresh rate is used when determining whether a mode is unique.

DDEDM_STANDARDVGAMODES   Enumerates Mode 13 in addition to the 320 × 200 × 8 Mode X mode.

lpDDSurfaceDesc2The address of a DDSURFACEDESC2 structure to be checked against available modes. If this parameter is NULL, all modes will be enumerated.
lpContextThe address of an application-defined structure that will be passed to each enumeration member.
lpEnumModesCallbackThe address of the EnumModesCallback2 function that the enumeration procedure will call each time a match is found.

The code to enumerate the display modes is shown below. The main routine used to enumerate the display modes is the ModeEnumCallback function. This routine will build a list of the available display modes. This list is stored in the pDevice->pddsdModes array.

 //------------------------------------------------------------------- // Name: ModeEnumCallback // Desc: Callback function for enumerating display modes //------------------------------------------------------------------- static HRESULT WINAPI ModeEnumCallback( DDSURFACEDESC2* pddsd,                                         VOID* pParentInfo ) {     D3DEnum_DeviceInfo* pDevice = (D3DEnum_DeviceInfo*)pParentInfo;     // Reallocate storage for the modes.     DDSURFACEDESC2* pddsdNewModes =          new DDSURFACEDESC2[pDevice->dwNumModes+1];     memcpy( pddsdNewModes, pDevice->pddsdModes,             pDevice->dwNumModes * sizeof(DDSURFACEDESC2) );     delete pDevice->pddsdModes;     pDevice->pddsdModes = pddsdNewModes;     // Add the new mode.     pDevice->pddsdModes[pDevice->dwNumModes++] = (*pddsd);     return DDENUMRET_OK; } 



Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net