Platform SDK: DirectX

Step 2.2: Test the Device

[C++]

This section pertains only to application development in Visual Basic. See Direct3D Immediate Mode C/C++ Tutorials.

[Visual Basic]

The following code fragment illustrates a way to determine device capabilities. The Enumeration application uses the following algorithm to choose a supported display mode for the given device:

  1. Return a video mode description for the specified element in the DirectDrawEnumModes object.
  2. Retrieve the bits per pixel support in the returned video mode description.
  3. Retrieve the given device's rendering depth.
  4. Check to see if the video mode of the specified element in the DirectDrawEnumModes object is compatible with the given device's rendering depth. If it is, then accept the display mode; otherwise, reject it. Skip all 8-bit modes.

The Enumeration application executes the following code to implement the algorithm:

    For j = 1 To g_ddEnumModes.GetCount()
        ' We have not tested this display mode yet, so assume it is not compatible.
        bCompatible = False
        ' Step 1:
        g_ddEnumModes.GetItem j, g_enumInfo
                
        ' Step 2:
        modeDepth = g_enumInfo.ddpfPixelFormat.lRGBBitCount
        
        ' Step 3:
        bitDepth = deviceDesc.lDeviceRenderBitDepth
        
        ' Step 4:
        If (32 = modeDepth) And (bitDepth And DDBD_32) Then bCompatible = True
        If (24 = modeDepth) And (bitDepth And DDBD_24) Then bCompatible = True
        If (16 = modeDepth) And (bitDepth And DDBD_16) Then bCompatible = True
        
        ' Populate the combo box with only the display modes that we want.
        If bCompatible Then
            cmbMode.AddItem Str(g_enumInfo.lWidth) + " x" + Str(g_enumInfo.lHeight) + " x" + Str(g_enumInfo.ddpfPixelFormat.lRGBBitCount)
        End If
    Next j

After this algorithm completes, the combo box, cmbMode, will hold a list display modes that meet the specified criteria, all other display modes will be ignored.