VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CVidCap"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Declare Function capGetDriverDescription Lib "avicap32.dll" _
    Alias "capGetDriverDescriptionA" (ByVal wDriverIndex As Long, _
    ByVal lpszName As String, _
    ByVal cbName As Long, _
    ByVal lpszVer As String, _
    ByVal cbVer As Long) As Boolean
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" _
    Alias "capCreateCaptureWindowA" (ByVal lpszWindowName As String, _
    ByVal dwStyle As Long, ByVal x As Long, _
    ByVal y As Long, ByVal nWidth As Long, _
    ByVal nHeight As Long, ByVal hWndParent As Long, _
    ByVal nID As Long) As Long
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000
Private Const WM_USER = &H400
Private Const WM_CAP_START = WM_USER
Private Const WM_CAP_DRIVER_CONNECT = (WM_CAP_START + 10)
Private Const WM_CAP_DRIVER_DISCONNECT = (WM_CAP_START + 11)
Private Const WM_CAP_EDIT_COPY = WM_USER + 30
Private Const WM_CAP_GRAB_FRAME_NOSTOP = (WM_CAP_START + 61)
Private Const WM_CAP_STOP = (WM_CAP_START + 68)
Private Const WM_CAP_DLG_VIDEOFORMAT = (WM_CAP_START + 41)
Private Const WM_CAP_DLG_VIDEOSOURCE = (WM_CAP_START + 42)
Private ChWnd As Long
Private DeviceID As Long
Public Function Init(ahWnd As Long, aDeviceId As Long) As Boolean
ChWnd = capCreateCaptureWindow("VidCap", WS_CHILD + WS_VISIBLE, 0, 0, 0, 0, ahWnd, aDeviceId)
Init = (ChWnd <> 0)
DeviceID = aDeviceId
End Function
Public Function GetCapDriverName(aIndex As Long, aName As String) As Boolean
Dim Ln As Long, Lv As Long
Dim Ver As String
Ln = 255
Lv = 255
aName = Space(Ln)
Ver = Space(Lv)
GetCapDriverName = capGetDriverDescription(aIndex, aName, Ln, Ver, Lv)
aName = Left(aName, InStr(1, aName, Chr(0)) - 1)
End Function


Public Sub Connect()
SendMessage ChWnd, WM_CAP_DRIVER_CONNECT, DeviceID, 0
End Sub

Public Sub Disconnect()
SendMessage ChWnd, WM_CAP_STOP, 0, 0
SendMessage ChWnd, WM_CAP_DRIVER_DISCONNECT, 0, 0
End Sub


Public Function Capture() As StdPicture
If ChWnd <> 0 Then
    SendMessage ChWnd, WM_CAP_GRAB_FRAME_NOSTOP, 0, 0
    SendMessage ChWnd, WM_CAP_EDIT_COPY, DeviceID, 0
    Set Capture = Clipboard.GetData()
End If
End Function


Public Sub OpenDlgVideoFormat()
If ChWnd <> 0 Then
 SendMessage ChWnd, WM_CAP_DLG_VIDEOFORMAT, 0, 0
End If
End Sub

Public Sub OpenDlgVideoSource()
If ChWnd <> 0 Then
 SendMessage ChWnd, WM_CAP_DLG_VIDEOSOURCE, 0, 0
End If
End Sub


