473,715 Members | 5,945 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Capture video from webcam and displays in picture box

debasisdas
8,127 Recognized Expert Expert
This program checks if webcam is available, if available then capture video and displays in picture box.

Add this code to the general module (.BAS file)
----------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Public Const ws_child As Long = &H40000000
  2. Public Const ws_visible As Long = &H10000000
  3.  
  4. Global Const WM_USER = 1024
  5. Global Const wm_cap_driver_connect = WM_USER + 10
  6. Global Const wm_cap_set_preview = WM_USER + 50
  7. Global Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
  8. Global Const WM_CAP_DRIVER_DISCONNECT As Long = WM_USER + 11
  9. Public Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_USER + 41
  10. 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
  11. 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
Add 4 command buttons and a picture box to the form
Add the following code to click en\vent of the respective buttons.

Expand|Select|Wrap|Line Numbers
  1. 'General Declaration
  2. Dim hwdc As Long
  3. Dim startcap As Boolean
  4.  
  5. Private Sub cmdCapture_Click()
  6. Dim temp As Long
  7.  
  8.   hwdc = capCreateCaptureWindow("Debasis Das", ws_child Or ws_visible, 0, 0, 320, 240, Picture1.hWnd, 0)
  9.   If (hwdc <> 0) Then
  10.     temp = SendMessage(hwdc, wm_cap_driver_connect, 0, 0)
  11.     temp = SendMessage(hwdc, wm_cap_set_preview, 1, 0)
  12.     temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 0)
  13.     startcap = True
  14.     Else
  15.     MsgBox ("No Webcam found")
  16.   End If
  17. End Sub
  18.  
  19. Private Sub cmdClose_Click()
  20. Dim temp As Long
  21. If startcap = True Then
  22. temp = SendMessage(hwdc, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
  23. startcap = False
  24. End If
  25. End Sub
  26.  
  27. Private Sub cmdexit_Click()
  28. Unload Me
  29. End Sub
  30.  
  31. Private Sub cmdVideoFormat_Click()
  32.  Dim temp As Long
  33.  If startcap = True Then
  34.   temp = SendMessage(hwdc, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
  35. End If
  36. End Sub
  37.  
To achieve this two API function are used.

1.capCreateCaptur eWindow
2.SendMessage

Please find the details of the functions for more info .
Oct 9 '07 #1
2 31655
Charles S
1 New Member
I tried your Video Capture API/Program and it worked great...sort of. The first time I ran the code it worked fine. I exited the program and restarted it. Now I get nothing but a black picturebox and none of the other buttons work (except the EXIT Button). I am using VB 6 with Windows 7 (64). I'm lost. What is the problem? I only have one webcam attached to the computer.

If I restart my computer, this code works great the first time. Seems like something is not being reset when I exit the capture.

One other note..When I try to excute the code the second time (without a computer reboot) a "Video Source" box appears. Since I only have one webcam attached there is only one choice available. I press the "OK" button and the get the problem stated above.

Thanks,

Charles
Jul 22 '10 #2
tuxalot
200 New Member
Can this be modified to work in Access with VBA?
Dec 31 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1448
by: Kanaiya | last post by:
hello i want to use DirectX.Net in c# i am done it. and capture video but i want to take images from it how to do it. i am not found it please help me. bye. -- With regards, Gangani Kanaiya.
1
22947
by: kantrishi | last post by:
Can any body give me details how i would capture video stream through video camera and save it in my database/computer in windows media player format or in real plyaer. I would like to make webcast software so my work need capturing live video feed where i would convert video into file format for later webcasting. Thanks, Rishi Kant ********************************************************************** Sent via Fuzzy Software @...
1
1966
by: FMorales | last post by:
We need to access to a webcam in .net c# We need to show the video in a form from a web cam, and when push a buttom record it to a file ..... How can we do it ?? Samples on google (c# webcam) show only how to acquire one single image, no record video to a file
0
2704
by: Tsunami | last post by:
Hi to all: I have a big problem and I write to ask for help. Sorry if this message does not arrive to the apropriate group. I have selected them paying attention but I am not sure to do it well. I want to capture a fotogram of a media player control in VB6 and I capture the screen as in the section "Visual Basic 4.0 16/32 Capture Routines" of this URL:
2
3541
by: vmorikawa | last post by:
Please, does anyone knows how to capture the video from webcam to a webform ?? I found some examples but to Windows Forms. I would like to make an application to see what's happen in my house from anywhere . It´s possible ?
9
13369
by: aljosa | last post by:
i'm trying to capture video from camera/webcam using python. so far i haven't found any library that would allow me to do that. cross-platform solution related to SDL/pygame would be nice but a simple solution to capture video under windows is ok. Aljosa Mohorovic
2
4317
by: Joseph Chase | last post by:
Is there a cross-platform solution for video capture from a webcam? I am aware of the Win32 videocapture library, but am unaware of how to accomplish the same functionality on the Mac side. Thanks in advance.
0
1481
by: chrisstorm | last post by:
hi, I know there are many examples and codes out there, I spent plenty of time searching around but still haven`t found what I am looking for (great - sounds like a song from U2). I have to capture video from webcams (regardless of their brand, if possible), either directly connected to XP or Vista workstations or connected via ethernet (ip cams). the first target is to get pictures from directly connected cams. first i thought using...
0
8821
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9340
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9103
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2118
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.