My Third Capture (Visual FoxPro 6.0)

The ltmmCaptureCtrl object allows the user to capture data from video and audio hardware devices. Using the following steps:

1.

Start with the form that you created in My First Capture.

2.

Add 2 combo boxes to you form. Name them cbVideoDev and cbAudioDev, respectively and change their Style property to 2 (Drop Down List)

3.

Update the Form Init procedure as follows:

&& use preview
ThisForm.ltmmCaptureCtrl1.Preview = .T.
&& select first video device
ThisForm.ltmmCaptureCtrl1.VideoDevices.Selection = 0

&& Set the Target File.
ThisForm.ltmmCaptureCtrl1.TargetFile = 'c:\target.avi'

&& Enumerate the Video\Audio devices.
&& Removing the Old video devices combo Items
ThisForm.cbVideoDev.Clear
devices = ThisForm.ltmmCaptureCtrl1.VideoDevices
Count = devices.Count
&& Adding the 'None' Item.
ThisForm.cbVideoDev.AddItem("None")
&& set the item data to -1 to use it when we will set the Selection Property.
ThisForm.cbVideoDev.ItemData(ThisForm.cbVideoDev.NewIndex) = -1

If Count > 0 Then
   && Select the first device. 
   devices.Selection = 0
   && Adding the Video Devices to the Video Device combo box. 
   For i = 0 to count-1 do
      device = devices.Item (i) 
      && Get the Device name and create the Combo item. 
      ThisForm.cbVideoDev.AddItem(device.FriendlyName
      && set the Tag to i to use it when we will set the Selection Property. 
      ThisForm.cbVideoDev.ItemData(ThisForm.cbVideoDev.NewIndex) = i
   Next
EndIf

&& Removing the Old audio devices combo Items
ThisForm.cbAudioDev.Clear
devices = ThisForm.ltmmCaptureCtrl1.AudioDevices
Count = devices.Count
&& Adding the 'None' Item. 
ThisForm.cbAudioDev.AddItem("None")
&& set the item data to -1 to use it when we will set the Selection Property. 
ThisForm.cbAudioDev.ItemData(ThisForm.cbAudioDev.NewIndex) = -1
If Count > 0 Then
   && Select the first device. 
   devices.Selection = 0
   && Adding the Audio Devices to the Audio Device combo box. 
   For i = 0 to count-1 do
      device = devices.Item (i) 
      && Get the Device name and create the Combo item. 
      ThisForm.cbAudioDev.AddItem(device.FriendlyName
      && set the Tag to i to use it when we will set the Selection Property. 
      ThisForm.cbAudioDev.ItemData(ThisForm.cbAudioDev.NewIndex) = i
   Next
EndIf
ThisForm.UpdateComBoxes()

4.

Update the btnStartCapture Click procedure to be as follows.

#define ltmmCapture_Mode_VideoOrAudio 0
ThisForm.ltmmCaptureCtrl1.StartCapture (ltmmCapture_Mode_VideoOrAudio) 

5.

On the Form menu, select New Method. Name the new method UpdateComBoxes and code its procedure as follows:

devices = ThisForm.ltmmCaptureCtrl1.VideoDevices
index = devices.Selection
With ThisForm.cbVideoDev
   For i = 1 to .ListCount do
      If .ItemData(i) = index Then
         .ListIndex = i
         Exit && For
      EndIf
   Next
EndWith
devices = ThisForm.ltmmCaptureCtrl1.AudioDevices
index = devices.Selection
With ThisForm.cbAudioDev
   For i = 1 to .ListCount do
      If .ItemData(i) = index Then
         .ListIndex = i
         Exit && For
      EndIf
   Next
EndWith

6.

Code the cbVideoDev combo box Click procedure as follows.

ThisForm.MousePointer = 11 && Hourglass
ThisForm.ltmmCaptureCtrl1.VideoDevices.Selection = ; 
   ThisForm.cbVideoDev.ItemData(ThisForm.cbVideoDev.ListIndex) 
ThisForm.MousePointer = 0 && Default

7.

Code the cbAudioDev combo box Click procedure as follows.

ThisForm.MousePointer = 11 && Hourglass
ThisForm.ltmmCaptureCtrl1.AudioDevices.Selection = ; 
   ThisForm.cbAudioDev.ItemData(ThisForm.cbAudioDev.ListIndex) 
ThisForm.MousePointer = 0 && Default

8.

Code the ltmmCaptureCtrl1 Complete procedure as follows.

ThisForm.Caption = 'Complete'

9.

Code the ltmmCaptureCtrl1 ErrorAbort procedure as follows.

LPARAMETERS errorcode
ThisForm.Caption = 'Aborted'
MessageBox('Capture Aborted. Error ' + Str(ErrorCode)) 

10.

Code the ltmmCaptureCtrl1 Progress procedure as follows.

LPARAMETERS time
#define ltmmCapture_Mode_ManualFrames 4
#define ltmmCapture_Mode_Still 6
str1 = 'Dropped ' + Str(ThisForm.ltmmCaptureCtrl1.NumDropped
str2 = 'Not Dropped ' + Str(ThisForm.ltmmCaptureCtrl1.NumNotDropped
str3= 'Frm. Size ' + Str(ThisForm.ltmmCaptureCtrl1.AverageFrameSize
If (ThisForm.ltmmCaptureCtrl1.Mode = ltmmCapture_Mode_Still) Or (ThisForm.ltmmCaptureCtrl1.Mode = ltmmCapture_Mode_ManualFrames) Then
   str4= ''
Else
   str4= Str(ThisForm.ltmmCaptureCtrl1.CaptureTime
EndIf
ThisForm.Caption = str1 + ' ' + str2 + ' ' + str3 + ' ' + str4

11.

Code the ltmmCaptureCtrl1 Started procedure as follows.

ThisForm.Caption = 'Started'

12.

Run your program to test it.