Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As
Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
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
Dim ctCapWin As Long, ctAviPath As String, ctPicPath As String, ctConnect As Boolean
'视频窗口控制消息常数
Const WS_Child = &H40000000: Const WS_Visible = &H10000000
Const WS_Caption = &HC00000: Const WS_ThickFrame = &H40000
Const WM_User = &H400 '用户消息开始号
Const WM_CAP_Connect = WM_User + 10 '连接一个摄像头
Const WM_CAP_DisConnect = WM_User + 11 '断开一个摄像头的连接
Const WM_CAP_Set_PreView = WM_User + 50 '使预览模式有效或者失效
Const WM_CAP_Set_Overlay = WM_User + 51 '使窗口处于叠加模式,也会自动地使预览
模式失效。
Const WM_CAP_Set_PreViewRate = WM_User + 52 '设置在预览模式下帧的显示频率
Const WM_CAP_Edit_Copy = WM_User + 30 '将当前图像复制到剪贴板
Const WM_CAP_Sequence = WM_User + 62 '开始录像,录像未结束前不会返回。
Const WM_Cap_File_Set_File = WM_User + 20 '设置当前的视频捕捉文件
Const WM_Cap_File_Get_File = WM_User + 21 '得到当前的视频捕捉文件
Private Sub Command1_Click()
'创建视频窗口和连接摄像头
Dim nStyle As Long, T As Long
If ctCapWin = 0 Then '创建一个视频窗口,大小:640*480
T = Me.ScaleY(Command1.Top + Command1.Height * 1.1, Me.ScaleMode, 3) '视频窗口垂
直位置:像素
'nStyle = WS_Child + WS_Visible + WS_Caption + WS_ThickFrame '子窗口(在 Form1 内)
+可见+标题栏+边框
'nStyle = WS_Child + WS_Visible '视频窗口无标题栏和边框
nStyle = WS_Visible '视频窗口为独立窗口,关闭主窗口视频窗口也会自动关闭
ctCapWin = capCreateCaptureWindow("视频监视中", nStyle, 0, T, 500, 400, Me.hWnd, 0)
End If
SendMessage ctCapWin, WM_CAP_Connect, 0, 0
'将视频窗口连接到摄像头,如无后面两条语句视频窗口画面不会变化
SendMessage ctCapWin, WM_CAP_Connect, 0, 0 '连接摄像头
SendMessage ctCapWin, WM_CAP_Set_PreView, 1, 0 '第三个参数:1-预览模式有效,0-
预览模式无效
SendMessage ctCapWin, WM_CAP_Set_PreViewRate, 30, 0 '第三个参数:设置预览显示频
评论0
最新资源