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
Sub Get_CaptureWindow(Optional ByVal nm As Long = 0)
'建立一个可抽取的窗口
'nm 为,若不只一个抽取装置的话,指定装置代号
CapHWnd = capCreateCaptureWindow("", WS_CHILD Or WS_VISIBLE, 0, 0, 160, 120, Screen.ActiveForm.hwnd, 0)
Call Connect_CaptureDriver(nm)
End Sub
Function Connect_CaptureDriver(ByVal nDriverIndex As Long) As Boolean
'链接到抽取装置
Dim retVal As Boolean
Dim Caps As CAPDRIVERCAPS
Dim I As Long
'Debug.Assert (nDriverIndex < 10) And (nDriverIndex >= 0)
'链接到抽取窗口的界面
retVal = SendMessage_Long(CapHWnd, WM_CAP_DRIVER_CONNECT, nDriverIndex, 0&)
If retVal = False Then Exit Function
'返回抽取界面的能力
retVal = SendMessage_Any(CapHWnd, WM_CAP_DRIVER_GET_CAPS, Len(Caps), Caps)
'设置每毫秒预览的速度
Call Set_PreviewRate(CapHWnd, 66) '15 FPS
'激活摄影机的预览图像
Call Set_Preview
'重新调整抽取窗口为全部占满图像
Call ResizeCaptureWindow
Connect_CaptureDriver = True
End Function