이 페이지는 아마도 필요한 것입니다. http://www.developerfusion.com/thread/46191/how-to-capture-picture-using-webcam-in-vb60/
'******************* module code **************
Public Const WS_CHILD As Long = &H40000000
Public Const WS_VISIBLE As Long = &H10000000
Public Const WM_USER As Long = &H400
Public Const WM_CAP_START As Long = WM_USER
Public Const WM_CAP_DRIVER_CONNECT As Long = WM_CAP_START + 10
Public Const WM_CAP_DRIVER_DISCONNECT As Long = WM_CAP_START + 11
Public Const WM_CAP_SET_PREVIEW As Long = WM_CAP_START + 50
Public Const WM_CAP_SET_PREVIEWRATE As Long = WM_CAP_START + 52
Public Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_CAP_START + 41
Public Const WM_CAP_FILE_SAVEDIB As Long = WM_CAP_START + 25
Public 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
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long _
, ByVal wParam As Long, ByRef lParam As Any) As Long
'************* end of module code ******************
Add the following controls in a form
1. A picture box with name "PicWebCam"
2. A commondialog control with name "CDialog"
3. Add 4 command buttons with name "cmd1","cmd2,"cmd3","cmd4"
then paste the following code
'************************** Code **************
Dim hCap As Long
Private Sub cmd4_Click()
Dim sFileName As String
Call SendMessage(hCap, WM_CAP_SET_PREVIEW, CLng(False), 0&)
With CDialog
.CancelError = True
.Flags = cdlOFNPathMustExist Or cdlOFNOverwritePrompt
.Filter = "Bitmap Picture(*.bmp)|*.bmp|JPEG Picture(*.jpg)|*.jpg|All Files|*.*"
.ShowSave
sFileName = .FileName
End With
Call SendMessage(hCap, WM_CAP_FILE_SAVEDIB, 0&, ByVal CStr(sFileName))
DoFinally:
Call SendMessage(hCap, WM_CAP_SET_PREVIEW, CLng(True), 0&)
End Sub
Private Sub Cmd3_Click()
Dim temp As Long
temp = SendMessage(hCap, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
End Sub
Private Sub Cmd1_Click()
hCap = capCreateCaptureWindow("Take a Camera Shot", WS_CHILD Or WS_VISIBLE, 0, 0, PicWebCam.Width, PicWebCam.Height, PicWebCam.hWnd, 0)
If hCap <> 0 Then
Call SendMessage(hCap, WM_CAP_DRIVER_CONNECT, 0, 0)
Call SendMessage(hCap, WM_CAP_SET_PREVIEWRATE, 66, 0&)
Call SendMessage(hCap, WM_CAP_SET_PREVIEW, CLng(True), 0&)
End If
End Sub
Private Sub Cmd2_Click()
Dim temp As Long
temp = SendMessage(hCap, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
End Sub
Private Sub Form_Load()
cmd1.Caption = "Start &Cam"
cmd2.Caption = "&Format Cam"
cmd3.Caption = "&Close Cam"
cmd4.Caption = "&Save Image"
End Sub
'**************** Code end ************************
기본적으로 어떻게이 사진을 촬영하도록 요청, 웹 캠 드라이버에 메시지를 보낼 창 메시지 펌프를 사용하고있다. 또한 미래의 자조를위한 팁. VBA와 거의 똑같은 VB6을 검색하면 더 나은 결과를 얻을 수 있습니다. VBA에는 몇 가지 기능 만 있습니다.
일반적인 대화 상자 컨트롤이없는 경우. 이 코드를 다음과 같이 바꿀 수 있습니다
Private Sub cmd4_Click()
Dim sFileName As String
Call SendMessage(hCap, WM_CAP_SET_PREVIEW, CLng(False), 0&)
sFileName="C:\PathToNewImageFile.bmp"
Call SendMessage(hCap, WM_CAP_FILE_SAVEDIB, 0&, ByVal CStr(sFileName))
DoFinally:
Call SendMessage(hCap, WM_CAP_SET_PREVIEW, CLng(True), 0&)
End Sub
답장을 보내 주시면 나는 "2. CDialog"라는 이름으로 commondialog 컨트롤에 문제가 있습니다. 2007 년 어디에서 찾을 수 있습니까? – YvetteLee
도구 메뉴를 클릭하십시오. 그런 다음 추가 컨트롤. "Microsoft 공용 대화 상자"컨트롤을 찾습니다. 그리고 그걸 확인해. 그런 다음 확인을 클릭하면 도구 상자에 새 항목이 나타납니다. 추가하려면 사용자 정의 폼에 그려서 아래쪽에있는 속성을 클릭하여 이름을 지정하십시오. 그러나 필자는 Excel 2013에서이 작업을 시도했지만 불가능했기 때문에 손가락이 엇갈 렸습니다. 그렇지 않으면 Windows API를 사용해야합니다. 저장 위치를 제공하는 용도로만 사용 된 것처럼 보입니다. 원하는 경우 테스트로 하드 코딩 할 수 있습니다. 답변 됨 updated –