VB不用控件联接摄像头
VB 不用控件联接摄像头,并保存图片为JPG我已于网上找到代码并实现了,并且用监视窗口的形式可以确定是否有其它程序在使用摄像头了,但碰到USB摄像头是联接就失效,
请各位大侠提供下VB 下能联接所有摄像头的代码,特别是USB的,谢谢了!
我只有这点分了,全给了,谢谢大大
以下代码为监控其它程序是否在使用摄像头的方法,请各位测试
'if Findvideo() = True then '其它程序正在使用摄像头
'if Findvideo() = False then '其它程序没有使用摄像头
Type wndClass
style As Long
lpfnwndproc As Long
cbClsextra As Long
cbWndExtra2 As Long
hInstance As Long
hIcon As Long
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
End Type
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public Function Findvideo() As Boolean
On Error Resume Next
Dim txtTitle As String
Dim lngHand As Long
Dim strName As String * 255
Dim wndClass As wndClass
Dim lngProcID As Long
Dim rctTemp As RECT
Findvideo = False
txtTitle = "ActiveMovie Window" '发现所有使用摄像头时都打开这个窗口"
lngHand = FindWindow(vbNullString, txtTitle)
GetClassName lngHand, strName, Len(strName)
GetWindowThreadProcessId lngHand, lngProcID
lblProcessID = lngProcID
If Left$(strName, 1) = vbNullChar Then
Findvideo = False
Else
If lblProcessID <> GetCurrentProcessId Then Findvideo = True ‘使用程序不是自已
End If
End Function