Live webcam viewer  
Author Message
nate-d-o-double-g





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

It might be a big job, but I'd like to know the (basic) code for a program that displays my **** video (live), and what control to display the **** video.



Visual Studio Express Editions33  
 
 
ahmedilyas





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

there was a thread about this a while ago, do a forum search and you should see something.

you would need a stream from the ****, its a tricky business however and will be a big challange to do. There is no control in .NET/Visual Studio for a **** feed, this you will have to create



 
 
Kramer_RSG





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

Nathan, there are many apps out there, including freeware, that does what you want. Included in the files are descriptions of how they did it too. Check freeware apps.

 
 
Ken Tucker





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

There is a sample on the Vb-Tips website.


 
 
nate-d-o-double-g





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

I've tryed the code you recommended, but the "Marshal" variable is not declared according to VB. I tryed to declare it myself, but I couldn't decipher what data type is was. have a look at this (the errors are bold, underscored, and italicized):

code
{

Public Class Form1

Const WM_CAP As Short = &H400S
Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10
Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11
Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30
Public Const WM_CAP_GET_STATUS As Integer = WM_CAP + 54
Public Const WM_CAP_DLG_VIDEOFORMAT As Integer = WM_CAP + 41

Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50
Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52
Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53
Const WS_CHILD As Integer = &H40000000
Const WS_VISIBLE As Integer = &H10000000
Const SWP_NOMOVE As Short = &H2S
Const SWP_NOSIZE As Short = 1
Const SWP_NOZORDER As Short = &H4S
Const HWND_BOTTOM As Short = 1

Dim iDevice As Integer = 0 ' Current device ID
Dim hHwnd As Integer ' Handle to preview window


Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
ByRef lParam As CAPSTATUS) As Boolean

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Boolean, _
ByRef lParam As Integer) As Boolean

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
ByRef lParam As Integer) As Boolean

Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean

Structure POINTAPI
Dim x As Integer
Dim y As Integer
End Structure

Public Structure CAPSTATUS
Dim uiImageWidth As Integer '// Width of the image
Dim uiImageHeight As Integer '// Height of the image
Dim fLiveWindow As Integer '// Now Previewing video
Dim fOverlayWindow As Integer '// Now Overlaying video
Dim fScale As Integer '// Scale image to client
Dim ptScroll As POINTAPI '// Scroll position
Dim fUsingDefaultPalette As Integer '// Using default driver palette
Dim fAudioHardware As Integer '// Audio hardware present
Dim fCapFileExists As Integer '// Does capture file exist
Dim dwCurrentVideoFrame As Integer '// # of video frames cap'td
Dim dwCurrentVideoFramesDropped As Integer '// # of video frames dropped
Dim dwCurrentWaveSamples As Integer '// # of wave samples cap'td
Dim dwCurrentTimeElapsedMS As Integer '// Elapsed capture duration
Dim hPalCurrent As Integer '// Current palette in use
Dim fCapturingNow As Integer '// Capture in progress
Dim dwReturn As Integer '// Error value after any operation
Dim wNumVideoAllocated As Integer '// Actual number of video buffers
Dim wNumAudioAllocated As Integer '// Actual number of audio buffers
End Structure

Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
(ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Short, ByVal hWndParent As Integer, _
ByVal nID As Integer) As Integer

Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _
ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadDeviceList()
If lstDevices.Items.Count > 0 Then
btnStart.Enabled = True
lstDevices.SelectedIndex = 0
btnStart.Enabled = True
Else
lstDevices.Items.Add("No Capture Device")
btnStart.Enabled = False
End If

Me.AutoScrollMinSize = New Size(100, 100)
btnStop.Enabled = False
btnSave.Enabled = False
Button1.Enabled = False
picCapture.SizeMode = PictureBoxSizeMode.StretchImage
End Sub

Private Sub LoadDeviceList()
Dim strName As String = Space(100)
Dim strVer As String = Space(100)
Dim bReturn As Boolean
Dim x As Short = 0

'
' Load name of all avialable devices into the lstDevices
'

Do
'
' Get Driver name and version
'
bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)

'
' If there was a device add device name to the list
'
If bReturn Then lstDevices.Items.Add(strName.Trim)
x += CType(1, Short)
Loop Until bReturn = False
End Sub

Private Sub OpenPreviewWindow()
Dim iHeight As Integer = picCapture.Height
Dim iWidth As Integer = picCapture.Width

'
' Open Preview window in picturebox
'
hHwnd = capCreateCaptureWindowA(iDevice.ToString, WS_VISIBLE Or WS_CHILD, 0, 0, 1280, _
1024, picCapture.Handle.ToInt32, 0)

'
' Connect to device
'
If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
'
'Set the preview scale
'
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)

'
'Set the preview rate in milliseconds
'
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)

'
'Start previewing the image from the camera
'
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)

'
' Resize window to fit in picturebox
'
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCapture.Width, picCapture.Height, _
SWP_NOMOVE Or SWP_NOZORDER)

btnSave.Enabled = True
btnStop.Enabled = True
btnStart.Enabled = False
Button1.Enabled = True
Else
'
' Error connecting to device close window
'
DestroyWindow(hHwnd)

btnSave.Enabled = False
End If
End Sub

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim r As Rectangle

iDevice = lstDevices.SelectedIndex
OpenPreviewWindow()
Dim bReturn As Boolean
Dim wSize As Integer
Dim s As CAPSTATUS
bReturn = SendMessage(hHwnd, WM_CAP_GET_STATUS, Marshal.SizeOf(s), s)
Debug.WriteLine(String.Format("Video Size {0} x {1}", s.uiImageWidth, s.uiImageHeight))
End Sub

Private Sub ClosePreviewWindow()
'
' Disconnect from device
'
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)

'
' close window
'

DestroyWindow(hHwnd)
End Sub

Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
ClosePreviewWindow()
btnSave.Enabled = False
btnStart.Enabled = True
Button1.Enabled = False
btnStop.Enabled = False
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim data As IDataObject
Dim bmap As Bitmap

'
' Copy image to clipboard
'
SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)

'
' Get image from clipboard and convert it to a bitmap
'
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
picCapture.Image = bmap
ClosePreviewWindow()
btnSave.Enabled = False
btnStop.Enabled = False
btnStart.Enabled = True
Button1.Enabled = False

Trace.Assert(Not (bmap Is Nothing))
If sfdImage.ShowDialog = Windows.Forms.DialogResult.OK Then
bmap.Save(sfdImage.FileName, Imaging.ImageFormat.Bmp)
End If

End If
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If btnStop.Enabled Then
ClosePreviewWindow()
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendMessage(hHwnd, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
End Sub

End Class

code
}


Notice that there is another error in the "Button1" subroutine.

Heeeeeeeelp! :'( lol



 
 
Ken Tucker





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

You need imports system.runtime.interopservices at the top of the code file

 
 
Microdan





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

I have just tried his and I cant figure out how to do it. sdfImage is not declared and SendMessage(hHwnd, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&) has got a VERY long error mesage:
Error 5 Overload resolution failed because no accessible 'SendMessage' can be called without a narrowing conversion:
'Declare Ansi Function SendMessage Lib "user32" Alias "SendMessageA" (hwnd As Integer, wMsg As Integer, wParam As Integer, ByRef lParam As Integer) As Boolean': Argument matching parameter 'wParam' narrows from 'Long' to 'Integer'.
'Declare Ansi Function SendMessage Lib "user32" Alias "SendMessageA" (hwnd As Integer, wMsg As Integer, wParam As Integer, ByRef lParam As Integer) As Boolean': Argument matching parameter 'lParam' narrows from 'Long' to 'Integer'.
'Declare Ansi Function SendMessage Lib "user32" Alias "SendMessageA" (hwnd As Integer, wMsg As Integer, wParam As Boolean, ByRef lParam As Integer) As Boolean': Argument matching parameter 'wParam' narrows from 'Long' to 'Boolean'.
'Declare Ansi Function SendMessage Lib "user32" Alias "SendMessageA" (hwnd As Integer, wMsg As Integer, wParam As Boolean, ByRef lParam As Integer) As Boolean': Argument matching parameter 'lParam' narrows from 'Long' to 'Integer'. C:\Documents and Settings\Tim\My Documents\Visual Studio 2005\Projects\Eye Toy\Eye Toy\Form1.vb 241 9 Eye Toy


How can I fix this to make it work

 
 
nate-d-o-double-g





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

uh-oh! not another incomprehensible error. any suggestions anyone else


 
 
John_Mac





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

Can anyone tell me where the constants such as WM_CAP_DLG_VIDEOFORMAT are defined   I have found code where some of them are defined (such as WM_CAP + 41 for the above) But there are many more references listed in the SDK that I would like to use.

 

Thanx

 

After a lot of Google searches, I found the definitions.  I believe they are defined in vbavicap.bas.  I am listing them here just in case anyone has this problem:

'// Defines start of the message range
Public Const WM_CAP_START = WM_USER

Public Const WM_CAP_GET_CAPSTREAMPTR = WM_CAP_START + 1

Public Const WM_CAP_SET_CALLBACK_ERROR = WM_CAP_START + 2
Public Const WM_CAP_SET_CALLBACK_STATUS = WM_CAP_START + 3
Public Const WM_CAP_SET_CALLBACK_YIELD = WM_CAP_START + 4
Public Const WM_CAP_SET_CALLBACK_FRAME = WM_CAP_START + 5
Public Const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START + 6
Public Const WM_CAP_SET_CALLBACK_WAVESTREAM = WM_CAP_START + 7
Public Const WM_CAP_GET_USER_DATA = WM_CAP_START + 8
Public Const WM_CAP_SET_USER_DATA = WM_CAP_START + 9
   
Public Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
Public Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
Public Const WM_CAP_DRIVER_GET_NAME = WM_CAP_START + 12
Public Const WM_CAP_DRIVER_GET_VERSION = WM_CAP_START + 13
Public Const WM_CAP_DRIVER_GET_CAPS = WM_CAP_START + 14

Public Const WM_CAP_FILE_SET_CAPTURE_FILE = WM_CAP_START + 20
Public Const WM_CAP_FILE_GET_CAPTURE_FILE = WM_CAP_START + 21
Public Const WM_CAP_FILE_ALLOCATE = WM_CAP_START + 22
Public Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
Public Const WM_CAP_FILE_SET_INFOCHUNK = WM_CAP_START + 24
Public Const WM_CAP_FILE_SAVEDIB = WM_CAP_START + 25

Public Const WM_CAP_EDIT_COPY = WM_CAP_START + 30

Public Const WM_CAP_SET_AUDIOFORMAT = WM_CAP_START + 35
Public Const WM_CAP_GET_AUDIOFORMAT = WM_CAP_START + 36

Public Const WM_CAP_DLG_VIDEOFORMAT = WM_CAP_START + 41
Public Const WM_CAP_DLG_VIDEOSOURCE = WM_CAP_START + 42
Public Const WM_CAP_DLG_VIDEODISPLAY = WM_CAP_START + 43
Public Const WM_CAP_GET_VIDEOFORMAT = WM_CAP_START + 44
Public Const WM_CAP_SET_VIDEOFORMAT = WM_CAP_START + 45
Public Const WM_CAP_DLG_VIDEOCOMPRESSION = WM_CAP_START + 46

Public Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
Public Const WM_CAP_SET_OVERLAY = WM_CAP_START + 51
Public Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
Public Const WM_CAP_SET_SCALE = WM_CAP_START + 53
Public Const WM_CAP_GET_STATUS = WM_CAP_START + 54
Public Const WM_CAP_SET_SCROLL = WM_CAP_START + 55

Public Const WM_CAP_GRAB_FRAME = WM_CAP_START + 60
Public Const WM_CAP_GRAB_FRAME_NOSTOP = WM_CAP_START + 61

Public Const WM_CAP_SEQUENCE = WM_CAP_START + 62
Public Const WM_CAP_SEQUENCE_NOFILE = WM_CAP_START + 63
Public Const WM_CAP_SET_SEQUENCE_SETUP = WM_CAP_START + 64
Public Const WM_CAP_GET_SEQUENCE_SETUP = WM_CAP_START + 65
Public Const WM_CAP_SET_MCI_DEVICE = WM_CAP_START + 66
Public Const WM_CAP_GET_MCI_DEVICE = WM_CAP_START + 67
Public Const WM_CAP_STOP = WM_CAP_START + 68
Public Const WM_CAP_ABORT = WM_CAP_START + 69

Public Const WM_CAP_SINGLE_FRAME_OPEN = WM_CAP_START + 70
Public Const WM_CAP_SINGLE_FRAME_CLOSE = WM_CAP_START + 71
Public Const WM_CAP_SINGLE_FRAME = WM_CAP_START + 72

Public Const WM_CAP_PAL_OPEN = WM_CAP_START + 80
Public Const WM_CAP_PAL_SAVE = WM_CAP_START + 81
Public Const WM_CAP_PAL_PASTE = WM_CAP_START + 82
Public Const WM_CAP_PAL_AUTOCREATE = WM_CAP_START + 83
Public Const WM_CAP_PAL_MANUALCREATE = WM_CAP_START + 84

'// Following added post VFW 1.1
Public Const WM_CAP_SET_CALLBACK_CAPCONTROL = WM_CAP_START + 85

'// Defines end of the message range
Public Const WM_CAP_END = WM_CAP_SET_CALLBACK_CAPCONTROL


 
 
MazterzDemon





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

I've tryed the code you recommended, but the "Marshal" variable is not declared according to VB. I tryed to declare it myself, but I couldn't decipher what data type is was. have a look at this (the errors are bold, underscored, and italicized):

code
{

Public Class Form1

Const WM_CAP As Short = &H400S
Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10
Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11
Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30
Public Const WM_CAP_GET_STATUS As Integer = WM_CAP + 54
Public Const WM_CAP_DLG_VIDEOFORMAT As Integer = WM_CAP + 41

Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50
Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52
Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53
Const WS_CHILD As Integer = &H40000000
Const WS_VISIBLE As Integer = &H10000000
Const SWP_NOMOVE As Short = &H2S
Const SWP_NOSIZE As Short = 1
Const SWP_NOZORDER As Short = &H4S
Const HWND_BOTTOM As Short = 1

Dim iDevice As Integer = 0 ' Current device ID
Dim hHwnd As Integer ' Handle to preview window


Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
ByRef lParam As CAPSTATUS) As Boolean

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Boolean, _
ByRef lParam As Integer) As Boolean

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
ByRef lParam As Integer) As Boolean

Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean

Structure POINTAPI
Dim x As Integer
Dim y As Integer
End Structure

Public Structure CAPSTATUS
Dim uiImageWidth As Integer '// Width of the image
Dim uiImageHeight As Integer '// Height of the image
Dim fLiveWindow As Integer '// Now Previewing video
Dim fOverlayWindow As Integer '// Now Overlaying video
Dim fScale As Integer '// Scale image to client
Dim ptScroll As POINTAPI '// Scroll position
Dim fUsingDefaultPalette As Integer '// Using default driver palette
Dim fAudioHardware As Integer '// Audio hardware present
Dim fCapFileExists As Integer '// Does capture file exist
Dim dwCurrentVideoFrame As Integer '// # of video frames cap'td
Dim dwCurrentVideoFramesDropped As Integer '// # of video frames dropped
Dim dwCurrentWaveSamples As Integer '// # of wave samples cap'td
Dim dwCurrentTimeElapsedMS As Integer '// Elapsed capture duration
Dim hPalCurrent As Integer '// Current palette in use
Dim fCapturingNow As Integer '// Capture in progress
Dim dwReturn As Integer '// Error value after any operation
Dim wNumVideoAllocated As Integer '// Actual number of video buffers
Dim wNumAudioAllocated As Integer '// Actual number of audio buffers
End Structure

Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
(ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Short, ByVal hWndParent As Integer, _
ByVal nID As Integer) As Integer

Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _
ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadDeviceList()
If lstDevices.Items.Count > 0 Then
btnStart.Enabled = True
lstDevices.SelectedIndex = 0
btnStart.Enabled = True
Else
lstDevices.Items.Add("No Capture Device")
btnStart.Enabled = False
End If

Me.AutoScrollMinSize = New Size(100, 100)
btnStop.Enabled = False
btnSave.Enabled = False
Button1.Enabled = False
picCapture.SizeMode = PictureBoxSizeMode.StretchImage
End Sub

Private Sub LoadDeviceList()
Dim strName As String = Space(100)
Dim strVer As String = Space(100)
Dim bReturn As Boolean
Dim x As Short = 0

'
' Load name of all avialable devices into the lstDevices
'

Do
'
' Get Driver name and version
'
bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)

'
' If there was a device add device name to the list
'
If bReturn Then lstDevices.Items.Add(strName.Trim)
x += CType(1, Short)
Loop Until bReturn = False
End Sub

Private Sub OpenPreviewWindow()
Dim iHeight As Integer = picCapture.Height
Dim iWidth As Integer = picCapture.Width

'
' Open Preview window in picturebox
'
hHwnd = capCreateCaptureWindowA(iDevice.ToString, WS_VISIBLE Or WS_CHILD, 0, 0, 1280, _
1024, picCapture.Handle.ToInt32, 0)

'
' Connect to device
'
If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
'
'Set the preview scale
'
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)

'
'Set the preview rate in milliseconds
'
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)

'
'Start previewing the image from the camera
'
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)

'
' Resize window to fit in picturebox
'
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCapture.Width, picCapture.Height, _
SWP_NOMOVE Or SWP_NOZORDER)

btnSave.Enabled = True
btnStop.Enabled = True
btnStart.Enabled = False
Button1.Enabled = True
Else
'
' Error connecting to device close window
'
DestroyWindow(hHwnd)

btnSave.Enabled = False
End If
End Sub

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim r As Rectangle

iDevice = lstDevices.SelectedIndex
OpenPreviewWindow()
Dim bReturn As Boolean
Dim wSize As Integer
Dim s As CAPSTATUS
bReturn = SendMessage(hHwnd, WM_CAP_GET_STATUS, Marshal.SizeOf(s), s)
Debug.WriteLine(String.Format("Video Size {0} x {1}", s.uiImageWidth, s.uiImageHeight))
End Sub

Private Sub ClosePreviewWindow()
'
' Disconnect from device
'
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)

'
' close window
'

DestroyWindow(hHwnd)
End Sub

Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
ClosePreviewWindow()
btnSave.Enabled = False
btnStart.Enabled = True
Button1.Enabled = False
btnStop.Enabled = False
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim data As IDataObject
Dim bmap As Bitmap

'
' Copy image to clipboard
'
SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)

'
' Get image from clipboard and convert it to a bitmap
'
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Bitmap)
picCapture.Image = bmap
ClosePreviewWindow()
btnSave.Enabled = False
btnStop.Enabled = False
btnStart.Enabled = True
Button1.Enabled = False

Trace.Assert(Not (bmap Is Nothing))
If sfdImage.ShowDialog = Windows.Forms.DialogResult.OK Then
bmap.Save(sfdImage.FileName, Imaging.ImageFormat.Bmp)
End If

End If
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If btnStop.Enabled Then
ClosePreviewWindow()
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendMessage(hHwnd, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
End Sub

End Class

code
}


Notice that there is another error in the "Button1" subroutine.

Heeeeeeeelp! Crying lol

thats Becuz that code is in C# Code. "Dee Dee Dee"



 
 
jo0ls





PostPosted: Visual Basic Express Edition, Live webcam viewer Top

code

{

...

code

}

must be some tag to format code on a webpage somewhere. The stuff inside IS vb.net.

The problem is with the line:

SendMessage(hWnd, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)

When you use an ampersand: 0&, it makes it a long. In vb.net a long is 64 bits long. SendMessage expects an Integer which is 32bits. Just remove the ampersand. The code was originally vb6.

Regarding constant definitions, these api functions are written in c/c++. The constants are defined in the header files. You can usually google for them by using

"#Define constantName"

Or download the platform sdk, look in the library at the information on the method, read which header file has declarations in, and look at the header file (*.h).

Anyway, this is an old thread, nothing to see here, move along...