Selecting ltmmConvertCtrl Object TargetFormats Example for Visual Basic

The following code demonstrates how to enumerate, add, and select ltmmConvertCtrl object target formats:

Sub EnumerateTargetFormats(TargetFormats As ltmmTargetFormats, List As ListBox)
    ' Build the formats list box
    Dim Selected As Long
    Selected = -1
    List.Clear
    For i = 0 To (TargetFormats.Count - 1)
        List.AddItem TargetFormats.Item(i).Name 
        List.ItemData(List.NewIndex) = i
        If TargetFormats.Item (i).Selected Then
            Selected = i
        End If
    Next
    ' highlight the current selection
    For i = 0 To (List.ListCount - 1)
        If List.ItemData(i) = Selected Then
            List.Selected(i) = True
        End If
    Next
End Sub
Sub SelectTargetFormat(TargetFormats As ltmmTargetFormats, List As ListBox)
    ' select the highlighted format
    TargetFormats.Selection = List.ItemData(List.ListIndex)
End Sub
Sub AddCustomTargetFormats(TargetFormats As ltmmTargetFormats)
    
    TargetFormats.RemoveAll 

' since we are just adding one entry you could use the following as an alternative
'   TargetFormats.Remove(TargetFormats.Count - 1)
    
    TargetFormats.Add "CUSTOM FORMAT 1", -1
    Index = TargetFormats.Count - 1
    ' MP3 audio compressor
    TargetFormats.Item(Index).AudioCompressor = "@device:cm:{33D9A761-90C8-11D0-BD43-00A0C911CE86}\85MPEG Layer-3"
    ' LEAD video compressor
    TargetFormats.Item (Index).VideoCompressor = "@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\LEAD MCMP/MJPEG Codec A COmpressor Also known as an encoder, this is a module or algorithm to compress data. Playing that data back requires a decompressor, or decoder. combined with a DECompressor, or encoder Also known as compressor, this is a module or algorithm to compress data. Playing that data back requires a decompressor, or decoder. and a decoder Also known as a decompressor, this is a module or algorithm to decompress data., which allows you to both compress and decompress that same data. (2.0)"
    ' no AVMux
    TargetFormats.Item (Index).AVMux = ""
    ' AVI Mux
    TargetFormats.Item (Index).Mux = "@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\{E2510970-F137-11CE-8B67-00AA00A3F1A6}"
    ' MEDIASUBTYPE_Avi
    TargetFormats.Item (Index).SinkSubType = "{E436EB88-524F-11CE-9F53-0020AF0BA770}"
    ' default sink
    TargetFormats.Item (Index).Sink = ""
End Sub
Private Sub Form_Load()
    ' build the target format list
    AddCustomTargetFormats ltmmConvertCtrl1.TargetFormats
    i = ltmmConvertCtrl1.TargetFormats.Find("AVI")
    If (i >= 0) Then
        ltmmConvertCtrl1.TargetFormats.Selection = i
    End If
    EnumerateTargetFormats ltmmConvertCtrl1.TargetFormats, lstTargetFormats
End Sub

Private Sub lstTargetFormats_Click()
    ' select the target format
    SelectTargetFormat ltmmConvertCtrl1.TargetFormats, lstTargetFormats
End Sub