Click here to Skip to main content
15,895,142 members
Articles / Programming Languages / VBScript
Article

Accessing WebCam in Visual Basic 6

Rate me:
Please Sign up or sign in to vote.
3.50/5 (19 votes)
11 Mar 2006CPOL 296.8K   13.1K   37   27
Accessing WebCam in Visual Basic 6

Introduction

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_SET_PREVIEWRATE = WM_USER + 52
Global Const WM_CAP_DRIVER_DISCONNECT As Long = WM_USER + 11
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
    Else
    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 dixanta@hotmail.com

License

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


Written By
President Creators Institute of Business & Technology
Nepal Nepal
Hi,

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

Find more videos at https://creators.institute/video

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:
dixanta@gmail.com

Website: https://creators.institute
Facebook: https://www.facebook.com/creators.ibt

Thank you

Comments and Discussions

 
Generala request from GHANASHYAM Pin
Sean Ewington11-Oct-07 3:22
staffSean Ewington11-Oct-07 3:22 
Questionhelp !!! Pin
mrqi29-Aug-07 6:44
mrqi29-Aug-07 6:44 
QuestionVB 2005 implementation? Pin
John_Mac20-Aug-06 15:57
John_Mac20-Aug-06 15:57 
AnswerRe: VB 2005 implementation? Pin
Cosi Fan Tutte23-Jan-07 20:55
Cosi Fan Tutte23-Jan-07 20:55 
Questionhow to capture & save in image format Pin
Kautsar29-Apr-06 12:39
Kautsar29-Apr-06 12:39 
AnswerRe: how to capture & save in image format Pin
lengochuan19-Nov-06 3:35
lengochuan19-Nov-06 3:35 
QuestionReal rate? Pin
ed id16-Mar-06 4:53
ed id16-Mar-06 4:53 
QuestionArticle? Pin
jonathan1513-Mar-06 3:37
jonathan1513-Mar-06 3:37 
The code may be useful to some but sadly as an article this sucks.
It has no content and explains nothing.
It is nothing more than a code snippet and is doubtfull that it is much use to a begginer without any other form of documentation.

If you re-write it and flesh it out a bit you may get more interest than the 1 votes you are getting at the moment (I voted you a 1 by the way but at least i left a comment so you know why. Many will not).

Jonathan

-- modified at 10:45 Monday 13th March, 2006

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.