开发者

How can I detect if there is a webcam connected to the PC?

I have the source code for taking a picture via webcam, but I need to know if there's a webcam connected to the PC. If there开发者_如何转开发's no webcam, the program won't call the function for taking photos. If necessary, I need to know which window's Api I have to use in this case.

Language: Visual Basic 6 using windows Apis.


The problem with the WIA is that not all devices are compatible. But I found the solution myself: SendMessage and capCreateCaptureWindowA work together. If there's no camera, SendMessage returns a "0". This is the code:

mCapHwnd = capCreateCaptureWindowA("WebCap", 0, 0, 0, m_Width, m_Height, Me.hwnd, 0)
DoEvents
If SendMessage(mCapHwnd, WM_CAP_CONNECT, 0, 0) <> 0 Then
Call SendMessage(mCapHwnd, WM_CAP_CONNECT, 0, 0)
DoEvents
Call SendMessage(mCapHwnd, WM_CAP_SET_PREVIEW, 0, 0)
Else
MsgBox "No Camera Detected"
End If

I hope somebody can find this useful :)


I think there's a flash app for that, if you're working on a website. Otherwise you might want to look into the Windows Image Acquisition API.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜