The following code demonstrates how to enumerate and select ltmmCaptureCtrl devices:
Sub EnumerateDevices(Devices As ltmmDevices, List As ListBox)
' Build the devices list box
Dim Selected As Long
Selected = -1
List.Clear
For i = 0 To (Devices.Count - 1)
List.AddItem Devices.Item (i).FriendlyName
List.ItemData(List.NewIndex) = i
If Devices.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 RefreshDevices(Devices As ltmmDevices, List As ListBox)
Dim Selected As Long
Dim SelectedName As String
' save the currently selected device's name
Selected = Devices.Selection
If Selected >= 0 Then
SelectedName = Devices.Item (Selected).Name
End If
' refresh the device collection
Devices.Refresh
' if there was a previously selected device, reselect it
If Selected >= 0 Then
Devices.Selection = Devices.Find (SelectedName)
End If
' rebuild the listbox
EnumerateDevices Devices, List
End Sub
Sub SelectDevice(Devices As ltmmDevices, List As ListBox)
' select the highlighted device
Devices.Selection = List.ItemData(List.ListIndex)
End Sub
Private Sub cmdAudioRefresh_Click()
' refresh audio devices
RefreshDevices ltmmCaptureCtrl1.AudioDevices, lstAudioDevices
End Sub
Private Sub cmdVideoRefresh_Click()
' refresh video devices
RefreshDevices ltmmCaptureCtrl1.VideoDevices, lstVideoDevices
End Sub
Private Sub Form_Load()
' build the audio device list
EnumerateDevices ltmmCaptureCtrl1.AudioDevices, lstAudioDevices
' build the video device list
EnumerateDevices ltmmCaptureCtrl1.VideoDevices, lstVideoDevices
End Sub
Private Sub lstAudioDevices_Click()
' select the audio device
SelectDevice ltmmCaptureCtrl1.AudioDevices, lstAudioDevices
End Sub
Private Sub lstVideoDevices_Click()
' select the video device
SelectDevice ltmmCaptureCtrl1.VideoDevices, lstVideoDevices
End Sub