'/// <summary> '/// 開始顯示圖像 '/// </summary> Public Sub Start() If bStat Then Return End If bStat = True Dim lpszName(99) As Byte hWndC = capCreateCaptureWindowA(lpszName, WS_CHILD Or WS_VISIBLE, mLeft, mTop, mWidth, mHeight, mControlPtr, 0) If hWndC.ToInt32() <> 0 Then SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0) SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0) SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0) SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0) SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0) SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0) SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0) SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0) End If Return End Sub '/// <summary> '/// 停止顯示 '/// </summary> Public Sub [Stop]() SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0) bStat = False End Sub '/// <summary> '/// 抓圖 '/// </summary> '/// <param name= "path "> 要保存bmp文件的路徑 </param> Public Sub GrabImage(ByVal path As String) Dim hBmp As IntPtr = Marshal.StringToHGlobalAnsi(path) SendMessage(hWndC, WM_CAP_SAVEDIB, 0, hBmp.ToInt64()) End Sub '/// <summary> '/// 錄像 '/// </summary> '/// <param name= "path "> 要保存avi文件的路徑 </param> Public Sub Kinescope(ByVal path As String) Dim hBmp As IntPtr = Marshal.StringToHGlobalAnsi(path) SendMessage(hWndC, WM_CAP_FILE_SET_CAPTURE_FILEA, 0, hBmp.ToInt64()) SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0) End Sub '/// <summary> '/// 停止錄像 '/// </summary> Public Sub StopKinescope() SendMessage(hWndC, WM_CAP_STOP, 0, 0) End Sub End Class |