Microsoft DirectX 9.0

Displaying Closed Captioning in Visual Basic

This topic applies to Windows XP only.

To enable closed captioning (CC), the application must activate the closed captioning feature. For analog television, the application must also activate the data services feature. You can find the features by enumerating them from the Video Control's available features collection. To activate a feature, add it to the active features collection.

To activate the closed captioning feature, perform the following steps:

  1. Create a new MSVidFeatures collection.
  2. Enumerate the available features from the Video Control's MSVidCtl.FeaturesAvailable property.
  3. Compare each feature's class identifier (CLSID) against the CLSID of the CC feature. For analog, also check for the CLSID of the data services feature. If the CLSID matches, add that feature to your collection object. Store a reference to the CC feature in a variable for later use.
  4. Set the Video Control's MSVidCtl.FeaturesActive property equal to your collection object.

Perform these steps before calling MSVidCtl.Build or MSVidCtl.Run. Once the CC feature is in the active features collection, you can enable or disable closed captioning at any time by setting the CC feature's MSVidClosedCaptioning.Enable property. By default, the feature is disabled.

The following code example enables closed captioning for analog television:

Const CLSID_CC As String = "{7F9CB14D-48E4-43B6-9346-1AEBC39C64D3}"
Const CLSID_DATASVC As String = "{334125C0-77E5-11D3-B653-00C04F79498E}"
Private mCCFeature as MSVidClosedCaptioning

Dim colFeatures As New MSVidFeatures
Dim objFeature As IMSVidFeature

' Find the CC and Data Services features, and add them to the collection.
For Each objFeature In VidControl.FeaturesAvailable
    If objFeature.ClassID = CLSID_CC Then
        colFeatures.Add objFeature
        Set mCCFeature = objFeature
    ElseIf objFeature.ClassID = CLSID_DATASVC Then
        colFeatures.Add objFeature
    End If
Next
' Use this collection for the active features.
VidControl1.FeaturesActive = colFeatures
mCCFeature.Enable = True

In this example, the CLSID_CC and CLSID_DATASVC constants contain the CLSIDs of the features, in string format. The application compares these strings against the IMSVidDevice.ClassID property. For digital television, you could omit the ElseIf clause, unless you wanted the data services feature in order to receive IP data.

Once the CC feature is active, you can display captions by setting the CC feature's MSVidClosedCaptioning.Enable property to True. You can hide the captions again by setting this property to False.