Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21271

Webcam video capture using capCreateCaptureWindow & Windows 8.1

$
0
0
I have written this VB6 code to capture video from a webcam and put it into
PictureBox0. It works perfectly all the time on Vista but on Windows 8.1 it runs
perfectly the first time after boot-up but running it again after that it just
fills PictureBox0 with black. if I re-start the computer it works again but just the once.
My VB6 was installed from an installation disc from a local college course I attended in 2004 and I have also downloaded VB6 SP6. I seems to be working fine with all my other projects.
How can I fix this problem?

'This code is in Module1.bas
Option Explicit
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

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 Const CONNECT As Long = 1034
Public Const DISCONNECT As Long = 1035
Public Const GET_FRAME As Long = 1084
Public Const COPY As Long = 1054
Public Const ws_visible = &H10000000
Public Const ws_child = &H40000000
Public Const WM_USER = 1024
Public Const WM_CAP_SET_PREVIEW = WM_USER + 50
Public Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52
Public Const PREVIEWRATE = 30
Public mCapHwnd As Long

'This code is in Form1
Option Explicit

Sub Form_Load()
SetUpCaptureWindow
End Sub

Private Sub SetUpCaptureWindow()
'Setup a capture window ("CaptureWindow" can be any string)
mCapHwnd = capCreateCaptureWindow("CaptureWindow", ws_child Or ws_visible, 0, 0, Picture0.ScaleWidth, Picture0.ScaleHeight, Picture0.hwnd, 0)
If (mCapHwnd <> 0) Then
'Connect to capture device
SendMessage mCapHwnd, CONNECT, 0, 0
'Make the video in Picture0 run in real time
SendMessage mCapHwnd, WM_CAP_SET_PREVIEW, 1, 0
SendMessage mCapHwnd, WM_CAP_SET_PREVIEWRATE, PREVIEWRATE, 0
Else
MsgBox "Unable to capture video.", vbCritical
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
'The application is closing so tidy up!
SendMessage mCapHwnd, DISCONNECT, 0, 0 'Disconnect from capture source - if it is connected upon termination the program can become unstable
End Sub

Viewing all articles
Browse latest Browse all 21271

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>