VB6.0如何呼叫Webcam视讯

前端之家收集整理的这篇文章主要介绍了VB6.0如何呼叫Webcam视讯前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

应该不只写在模组,表单应该也要自行安插几个按钮和图片盒来对应。
按钮需有:cmdCapture、cmdClose、cmdVideoFormat,外加一个PictureBox:Picture1
1、使用时接上webcam但要关闭其原本的观看软体
2、按下cmdCapture,此时可以看到影像
3、cmdVideoFormat可调整视讯格式
4、离开时按下cmdClose关闭


Module1模组中

代码:
'This program check whether webcam is available or not
' if available then capture and displays in [Box=Red]picture Box[/Box]
'Created by Dixanta Bahadur Shrestha
'Created Date: 12-March-2006
'Programmer does not garuntees ifnot functions well
Global Const ws_child As Long = &H40000000
Global Const ws_visible As Long = &H10000000
Global Const WM_USER = 1024
Global Const wm_cap_driver_connect = WM_USER + 10
Global Const wm_cap_set_preview = WM_USER + 50
Global Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
Global Const WM_CAP_DRIVER_DISCONNECT As Long = WM_USER + 11
Global Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_USER + 41
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
Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal a As String,ByVal b As Long,ByVal c As Integer,ByVal d As Integer,ByVal e As Integer,ByVal f As Integer,ByVal g As Long,ByVal h As Integer) As Long
Form1表单中:

代码:
Dim hwdc As Long
Dim startcap As Boolean
Private Sub cmdCapture_Click()
Dim temp As Long
hwdc = capCreateCaptureWindow("Dixanta Vision System",ws_child Or ws_visible,320,240,Picture1.hWnd,0)
If (hwdc <> 0) Then
temp = SendMessage(hwdc,wm_cap_driver_connect,0)
temp = SendMessage(hwdc,wm_cap_set_preview,1,WM_CAP_SET_PREVIEWRATE,30,0)
startcap = True
Else
MsgBox ("No Webcam found")
End If
End Sub

Private Sub cmdClose_Click()
Dim temp As Long
If startcap = True Then
temp = SendMessage(hwdc,WM_CAP_DRIVER_DISCONNECT,0&,0&)
startcap = False
End If
End Sub

Private Sub cmdVideoFormat_Click()
Dim temp As Long
If startcap = True Then
temp = SendMessage(hwdc,WM_CAP_DLG_VIDEOFORMAT,0&)
End If
End Sub

WM_USER是相对于每个不同API窗口所属的WM_消息, 此处是针对 capCreateCaptureWindow 建立的窗口,设定专属的WM_CAP..消息值 这些可以在搜寻 或是利用google来搜寻, 以下是在找到的片断WM_CAP宣告。 代码: {-- Window messages WM_CAP... which can be sent to an AVICAP window ----------} // UNICODE // // The Win32 version of AVICAP on NT supports UNICODE applications: // for each API or message that takes a char or string parameter,there are // two versions,ApiNameA and ApiNameW. The default name ApiName is #defined // to one or other depending on whether UNICODE is defined. Apps can call // the A and W apis directly,and mix them. // // The 32-bit AVICAP on NT uses unicode exclusively internally. // ApiNameA() will be implemented as a call to ApiNameW() together with // translation of strings. // Defines start of the message range const WM_CAP_START = WM_USER; WM_CAP_UNICODE_START = WM_USER + 100; WM_CAP_GET_CAPSTREAMPTR = WM_CAP_START + 1; WM_CAP_SET_CALLBACK_ERRORW = WM_CAP_UNICODE_START + 2; WM_CAP_SET_CALLBACK_STATUSW = WM_CAP_UNICODE_START + 3; WM_CAP_SET_CALLBACK_ERRORA = WM_CAP_START + 2; WM_CAP_SET_CALLBACK_STATUSA = WM_CAP_START + 3; WM_CAP_SET_CALLBACK_ERROR = WM_CAP_SET_CALLBACK_ERRORA; WM_CAP_SET_CALLBACK_STATUS = WM_CAP_SET_CALLBACK_STATUSA; WM_CAP_SET_CALLBACK_YIELD = WM_CAP_START + 4; WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START + 5; WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START + 6; WM_CAP_SET_CALLBACK_WAVESTREAM= WM_CAP_START + 7; WM_CAP_GET_USER_DATA = WM_CAP_START + 8; WM_CAP_SET_USER_DATA = WM_CAP_START + 9; WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10; WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11; WM_CAP_DRIVER_GET_NAMEA = WM_CAP_START + 12; WM_CAP_DRIVER_GET_VERSIONA = WM_CAP_START + 13; WM_CAP_DRIVER_GET_NAMEW = WM_CAP_UNICODE_START + 12; WM_CAP_DRIVER_GET_VERSIONW = WM_CAP_UNICODE_START + 13; WM_CAP_DRIVER_GET_NAME = WM_CAP_DRIVER_GET_NAMEA; WM_CAP_DRIVER_GET_VERSION = WM_CAP_DRIVER_GET_VERSIONA; WM_CAP_DRIVER_GET_CAPS = WM_CAP_START + 14; WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20; WM_CAP_FILE_GET_CAPTURE_FILEA = WM_CAP_START + 21; WM_CAP_FILE_SAVEASA = WM_CAP_START + 23; WM_CAP_FILE_SAVEDIBA = WM_CAP_START + 25; WM_CAP_FILE_SET_CAPTURE_FILEW = WM_CAP_UNICODE_START + 20; WM_CAP_FILE_GET_CAPTURE_FILEW = WM_CAP_UNICODE_START + 21; WM_CAP_FILE_SAVEASW = WM_CAP_UNICODE_START + 23; WM_CAP_FILE_SAVEDIBW = WM_CAP_UNICODE_START + 25; WM_CAP_FILE_SET_CAPTURE_FILE = WM_CAP_FILE_SET_CAPTURE_FILEA; WM_CAP_FILE_GET_CAPTURE_FILE = WM_CAP_FILE_GET_CAPTURE_FILEA; WM_CAP_FILE_SAVEAS = WM_CAP_FILE_SAVEASA; WM_CAP_FILE_SAVEDIB = WM_CAP_FILE_SAVEDIBA; // out of order to save on ifdefs WM_CAP_FILE_ALLOCATE = WM_CAP_START + 22; WM_CAP_FILE_SET_INFOCHUNK = WM_CAP_START + 24; WM_CAP_EDIT_COPY = WM_CAP_START + 30; WM_CAP_SET_AUdioFORMAT = WM_CAP_START + 35; WM_CAP_GET_AUdioFORMAT = WM_CAP_START + 36; WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41; WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42; WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43; WM_CAP_GET_VIDEOFORMAT = WM_CAP_START + 44; WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45; WM_CAP_DLG_VIDEOCOMPRESSION = WM_CAP_START + 46; WM_CAP_SET_PREVIEW = WM_CAP_START + 50; WM_CAP_SET_OVERLAY = WM_CAP_START + 51; WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52; WM_CAP_SET_SCALE = WM_CAP_START + 53; WM_CAP_GET_STATUS = WM_CAP_START + 54; WM_CAP_SET_SCROLL = WM_CAP_START + 55; WM_CAP_GRAB_FRAME = WM_CAP_START + 60; WM_CAP_GRAB_FRAME_NOSTOP = WM_CAP_START + 61; WM_CAP_SEQUENCE = WM_CAP_START + 62; WM_CAP_SEQUENCE_NOFILE = WM_CAP_START + 63; WM_CAP_SET_SEQUENCE_SETUP = WM_CAP_START + 64; WM_CAP_GET_SEQUENCE_SETUP = WM_CAP_START + 65; WM_CAP_SET_MCI_DEVICEA = WM_CAP_START + 66; WM_CAP_GET_MCI_DEVICEA = WM_CAP_START + 67; WM_CAP_SET_MCI_DEVICEW = WM_CAP_UNICODE_START + 66; WM_CAP_GET_MCI_DEVICEW = WM_CAP_UNICODE_START + 67; WM_CAP_SET_MCI_DEVICE = WM_CAP_SET_MCI_DEVICEA; WM_CAP_GET_MCI_DEVICE = WM_CAP_GET_MCI_DEVICEA; WM_CAP_STOP = WM_CAP_START + 68; WM_CAP_ABORT = WM_CAP_START + 69; WM_CAP_SINGLE_FRAME_OPEN = WM_CAP_START + 70; WM_CAP_SINGLE_FRAME_CLOSE = WM_CAP_START + 71; WM_CAP_SINGLE_FRAME = WM_CAP_START + 72; WM_CAP_PAL_OPENA = WM_CAP_START + 80; WM_CAP_PAL_SAVEA = WM_CAP_START + 81; WM_CAP_PAL_OPENW = WM_CAP_UNICODE_START + 80; WM_CAP_PAL_SAVEW = WM_CAP_UNICODE_START + 81; WM_CAP_PAL_OPEN = WM_CAP_PAL_OPENA; WM_CAP_PAL_SAVE = WM_CAP_PAL_SAVEA; WM_CAP_PAL_PASTE = WM_CAP_START + 82; WM_CAP_PAL_AUTOCREATE = WM_CAP_START + 83; WM_CAP_PAL_MANUALCREATE = WM_CAP_START + 84; // Following added post VFW 1.1 WM_CAP_SET_CALLBACK_CAPCONTROL= WM_CAP_START + 85; // Defines end of the message range WM_CAP_UNICODE_END = WM_CAP_PAL_SAVEW; WM_CAP_END = WM_CAP_UNICODE_END;

原文链接:https://www.f2er.com/vb/258172.html

猜你在找的VB相关文章