Click here to Skip to main content
13,346,397 members (64,756 online)
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 11 Mar 2006

Accessing WebCam in Visual Basic 6

, 11 Mar 2006
Rate this:
Please Sign up or sign in to vote.
Accessing WebCam in Visual Basic 6


This is a simple program and can be use to access webcam from the visual basic 6.

This program checks whether webcam is available or not. If not available simple gives

a message otherwise capture from the webcam and displays in picture box.

This program has 3 diffrent functionality.

  1. Capture from the webcam
  2. Close the webcam
  3. Format the video

Source Code

'This program check whether webcam is available or not
' if available then capture and displays in picture box

'Created by Dixanta Bahadur Shrestha
'Created Date: 12-March-2006

'Programmer does not garuntees if  not functions well

Global Const ws_child As Long = &H40000000
Global Const ws_visible As Long = &H10000000

Global Const WM_USER = 1024
Global Const wm_cap_driver_connect = WM_USER + 10
Global Const wm_cap_set_preview = WM_USER + 50
Global Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_USER + 41
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (
    ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, 
    ByVal lParam As Long) As Long
Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias 
    "capCreateCaptureWindowA" (
    ByVal a As String, ByVal b As Long, ByVal c As Integer, 
    ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, 
    ByVal g As Long, ByVal h As Integer) As Long


Dim hwdc As Long
Dim startcap As Boolean
Private Sub cmdCapture_Click()
Dim temp As Long

  hwdc = capCreateCaptureWindow("Dixanta Vision System", 
      ws_child Or ws_visible, 0, 0, 320, 240, Picture1.hWnd, 0)
  If (hwdc <> 0) Then
    temp = SendMessage(hwdc, wm_cap_driver_connect, 0, 0)
    temp = SendMessage(hwdc, wm_cap_set_preview, 1, 0)
    temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 0)
    startcap = True
    MsgBox ("No Webcam found")
  End If
End Sub

Private Sub cmdClose_Click()
Dim temp As Long
If startcap = True Then
temp = SendMessage(hwdc, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
startcap = False
End If
End Sub

Private Sub cmdVideoFormat_Click()
 Dim temp As Long
 If startcap = True Then
  temp = SendMessage(hwdc, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
End If
End Sub

Feel free to contact me at


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Australia Australia

Its Dixanta Shrestha here from Kathmandu, Nepal. I graduated from University of Ballarat(Sydney, Australia) in Bachelor's of Information Technology in 2005.

I started working as programmer since 2000 as visual Basic 6 and asp programmer. During my working period I worked on php,.net and java too and strong knowledge in Database like mysql,oracle,sql server and so on.

I enjoy programming and have finished several projects till now. Currently I work for my own and most of my clients are from Europe, Australia and America. So far I have positive feedback from all of my clients and hope that in future too.

If you are planning to give away your project on reasonable and competitive prices please feel free to contact me.

you can get me on following email addresses:

Thank you

You may also be interested in...

Comments and Discussions

Questiontanx Pin
farzan6116-May-16 22:04
memberfarzan6116-May-16 22:04 
QuestionThank you! Pin
universalbri8-May-15 12:24
memberuniversalbri8-May-15 12:24 
Questionintegarte cc camera IP Address in vb6 Pin
uma anasurya1-Feb-15 20:36
memberuma anasurya1-Feb-15 20:36 
Questioncompatibility?? Pin
Marc De Joya5-Jan-13 6:49
memberMarc De Joya5-Jan-13 6:49 
Questioncoding Pin
faizal asep19-Dec-12 9:51
memberfaizal asep19-Dec-12 9:51 
GeneralMy vote of 3 Pin
cheffzbros24-Jan-11 14:55
membercheffzbros24-Jan-11 14:55 
GeneralMy vote of 5 Pin
guidoespel2-Nov-10 14:08
memberguidoespel2-Nov-10 14:08 
GeneralMy vote of 4 Pin
Bee Nugraha8-Jul-10 1:25
memberBee Nugraha8-Jul-10 1:25 
GeneralMy vote of 5 Pin
santosh547129-Jun-10 10:44
membersantosh547129-Jun-10 10:44 
Generalunderstanding the code- can anyone explain this code. Pin
puneeth raj29-Jun-10 1:14
memberpuneeth raj29-Jun-10 1:14 
QuestionHow to Capture Images Solutions Pin
dixanta19-May-10 8:56
memberdixanta19-May-10 8:56 
QuestionHow to save it to pictures Pin
cskult19-Apr-10 6:44
membercskult19-Apr-10 6:44 
AnswerRe: How to save it to pictures Pin
dixanta19-May-10 8:56
memberdixanta19-May-10 8:56 
Generalhi Pin
itwasntm36-Sep-09 3:03
memberitwasntm36-Sep-09 3:03 
Generalcapture image Pin
shiv00138-Jul-09 5:25
membershiv00138-Jul-09 5:25 
Generalsave captured image in MS access Pin
madhu harchandani7-Dec-08 21:17
membermadhu harchandani7-Dec-08 21:17 
Questionwebcam image properties [modified] Pin
notsleepy25-Mar-08 2:52
membernotsleepy25-Mar-08 2:52 
GeneralError catching & alternative Pin
shadesbass18-Dec-07 11:02
membershadesbass18-Dec-07 11:02 
Generala request from GHANASHYAM Pin
Sean Ewington11-Oct-07 4:22
adminSean Ewington11-Oct-07 4:22 
Questionhelp !!! Pin
mrqi29-Aug-07 7:44
membermrqi29-Aug-07 7:44 
QuestionVB 2005 implementation? Pin
John_Mac20-Aug-06 16:57
memberJohn_Mac20-Aug-06 16:57 
AnswerRe: VB 2005 implementation? Pin
Cosi Fan Tutte23-Jan-07 21:55
memberCosi Fan Tutte23-Jan-07 21:55 
Questionhow to capture & save in image format Pin
Kautsar29-Apr-06 13:39
memberKautsar29-Apr-06 13:39 
AnswerRe: how to capture & save in image format Pin
lengochuan19-Nov-06 4:35
memberlengochuan19-Nov-06 4:35 
QuestionReal rate? Pin
ed id16-Mar-06 5:53
membered id16-Mar-06 5:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 12 Mar 2006
Article Copyright 2006 by dixanta
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid