Ecco il codice intero :
codice:
Imports System.Runtime.InteropServices
Imports System.Runtime
Public Class Form1
Dim WM_CAP_START As Integer = &H400S
Dim WS_CHILD As Integer = &H40000000
Dim WS_VISIBLE As Integer = &H10000000
Dim WM_CAP_DRIVER_CONNECT As Integer = WM_CAP_START + 10
Dim WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP_START + 11
Dim WM_CAP_EDIT_COPY As Integer = WM_CAP_START + 30
Dim WM_CAP_SEQUENCE As Integer = WM_CAP_START + 62
Dim WM_CAP_FILE_SAVEAS As Integer = WM_CAP_START + 23
Dim WM_CAP_SET_SCALE As Integer = WM_CAP_START + 53
Dim WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP_START + 52
Dim WM_CAP_SET_PREVIEW As Integer = WM_CAP_START + 50
Dim SWP_NOMOVE As Integer = &H2S
Dim SWP_NOSIZE As Integer = 1
Dim SWP_NOZORDER As Integer = &H4S
Dim HWND_BOTTOM As Integer = 1
'--dichiariamo la funzione utile al get di periferiche HW--
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" _
(ByVal wDriverIndex As Short, _
ByVal lpszName As String, ByVal cbName As Integer, _
ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean
'--Funzione per la cattura dell'immagine--
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 hWnd As Integer, _
ByVal nID As Integer) As Integer
'SendMessage
Declare Function SendMessage Lib "user32.dll" (ByVal hWnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Object) As Integer
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
Dim VideoSource As Integer
Dim hWnd As Integer
Private Sub InterrompiPreview()
SendMessage(hWnd, WM_CAP_DRIVER_DISCONNECT, VideoSource, 0)
DestroyWindow(hWnd)
End Sub
Private Sub VideoPreview()
hWnd = capCreateCaptureWindowA(VideoSource, WS_VISIBLE Or WS_CHILD, 0, 0, 0, _
0, PictureBox1.Handle.ToInt32, 0)
End Sub
Private Sub driver_disponibili()
Dim NomeDriver As String = Space(80)
Dim VersioneDriver As String = Space(80)
For i As Integer = 0 To 9
If capGetDriverDescriptionA(i, NomeDriver, 80, VersioneDriver, 80) Then
ListBox1.Items.Add(NomeDriver.Trim)
Button1.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
End If
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
driver_disponibili()
End Sub
Private Sub CaptureImage()
Dim data As IDataObject
Dim bmap As Image
'copiamo l'immagine nella clipboard---
SendMessage(hWnd, WM_CAP_EDIT_COPY, 0, 0)
'convertiamo il tutto in bmp
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), _
Image)
PictureBox1.Image = bmap
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
VideoPreview()
End Sub
End Sub
End Class