Primero declaramos las funciones SendMessage y capCreateCaptureWindow (si se declaran en un módulo .bas las declaraciones deben ser públicas, para este ejemplo asumiremos que todo el código está dentro de un Form):
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
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 Const CONNECT As Long = 1034
El código que nos dice si hay una webcam conectada es:
Dim mCapHwnd as Long
mCapHwnd = capCreateCaptureWindowA("WebCap", 0, 0, 0, 320, 240, Me.hwnd, 0)
DoEvents
If SendMessage(mCapHwnd, CONNECT, 0, 0) <> 0 Then
MsgBox "Se ha detectado una webcam conectada y lista para usarse"
Else
MsgBox "No se ha detectado una webcam"
End If
Basado en este código de Recursos Visual Basic
No hay comentarios:
Publicar un comentario