Platform SDK: DirectX

Step 1.1: Enumerate Driver Information

[Visual Basic]

The information in this section pertains only to applications written in C and C++. See Direct3D Immediate Mode Visual Basic Tutorials.

[C++]

The Enumeration application uses the following application-defined callback function to enumerate all of the DirectDraw devices installed on the system:

static BOOL WINAPI DriverEnumCallback( GUID* pGUID, LPSTR strDesc,
                                       LPSTR strName, VOID*, HMONITOR )

The first parameter, pGUID, is the address of the unique identifier of the DirectDraw object. The next two parameters are strings that describe and name the driver. For more information on this function, consult the DDEnumCallbackEx topic in the SDK reference.

Before you can enumerate driver information, you need to create a display driver. You can use the globally-unique identifier (GUID) that is passed into the DriverEnumCallback application-defined callback function to create a display driver for your application:

hr = DirectDrawCreateEx( pGUID, (VOID**)&pDD, IID_IDirectDraw7, NULL );

The NULL argument indicates that the active display driver should be used. At this point, the Enumeration application creates an IDirect3D7 object, which will be used to enumerate all of the Direct3D devices.

You can copy the driver data to a D3DDEVICEINFO structure, so that driver information can be passed to your application-defined callback functions:

    // Copy data to a device info structure
    ZeroMemory( &d3dDeviceInfo, sizeof(D3DDEVICEINFO) );
    strncpy( d3dDeviceInfo.strDesc, strDesc, 39 );
    d3dDeviceInfo.ddDriverCaps.dwSize = sizeof(DDCAPS);
    d3dDeviceInfo.ddHELCaps.dwSize    = sizeof(DDCAPS);
    pDD->GetCaps( &d3dDeviceInfo.ddDriverCaps, &d3dDeviceInfo.ddHELCaps );
    d3dDeviceInfo.pDriverGUID = pGUID;

Consult the following code sample and note that the ddsdModes member of the D3DDEVICEINFO structure is an array of DDSURFACEDESC2 types that will describe (list) the supported display modes for a particular device. Eventually, you will want to display a combo box to the user that lists the current display mode (windowed) followed by a list of the supported full-screen display modes for each device.

Note  The graphical user interface (GUI) design and structure of the Enumeration application is not explained in this tutorial, refer to the code in the SDK for this information.

The following code sample retrieves the display mode information for the current display mode settings:

    if( ( NULL == d3dDeviceInfo.pDriverGUID ) &&
        ( d3dDeviceInfo.ddDriverCaps.dwCaps2 & DDCAPS2_CANRENDERWINDOWED ) )
    {
        // Get the current display depth
        DEVMODE devmode;
        devmode.dmSize = sizeof(DEVMODE);
        EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &devmode );
 
        // Set up the mode info
        DDSURFACEDESC2* pMode = &d3dDeviceInfo.ddsdModes[0];
        pMode->ddpfPixelFormat.dwRGBBitCount = devmode.dmBitsPerPel;
        pMode->dwWidth  = 0;
        pMode->dwHeight = 0;
 
        d3dDeviceInfo.dwNumModes = 1;
    }

The preceding code sample illustrates how to fill the first element of the ddsdModes array with the current display settings. The remaining elements of the ddsdModes array will be filled after the full-screen display modes have been enumerated and selected for each device. Note that the EnumDisplaySettings method is used to obtain information about the current display depth. The depth settings are then saved in a DEVMODE structure, which are then copied into the ddpfPixelFormat.dwRGBBitCount member of the first element of the ddsdModes array:

        pMode->ddpfPixelFormat.dwRGBBitCount = devmode.dmBitsPerPel;

Now, that you have enumerated the DirectDraw drivers on your system and saved the current display settings, you are ready to enumerate display modes.

The details of display mode enumeration are illustrated in Step 1.2: Enumerate Display Mode Information.