Public Shared Function EnumDevices() As CapDevice()
Dim strName As String = Space(100)
Dim strVer As String = Space(100)
Dim bReturn As Boolean
Dim x As Integer = 0
Dim devices As New List(Of CapDevice)
' Load name of all avialable devices into the lstDevices .
Do
Dim cap As New CapDevice
' Get Driver name and version
bReturn = capGetDriverDescription(x, strName, 100, strVer, 100)
' If there was a device add device name to the list
cap.Name = strName.Trim
cap.Version = strVer
cap.iDeviceIdx = x
If bReturn Then devices.Add(cap)
x += 1
Loop Until bReturn = False
Return devices.ToArray()
End Function
Public Function StartCapture(ByVal parent As Control, Optional ByVal _
iDevice As Integer = 0, Optional ByVal AutoResize As Boolean = True) As _
Boolean
If active Then Return True
Dim iHeight As Integer = parent.Height
Dim iWidth As Integer = parent.Width
capparent = parent
' Open Preview window in picturebox .
' Create a child window with capCreateCaptureWindowA so you can display
' it in a picturebox.
capwnd = capCreateCaptureWindow(wndname, WS_VISIBLE Or WS_CHILD, 0, 0, _
640, _
480, parent.Handle.ToInt32, 0)
' Connect to device
If SendMessage(capwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
' Set the preview scale
SendMessage(capwnd, WM_CAP_SET_SCALE, True, 0)
' Set the preview rate in milliseconds
SendMessage(capwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
' Start previewing the image from the camera
SendMessage(capwnd, WM_CAP_SET_PREVIEW, True, 0)
Dim parentform As Control = parent
While parentform IsNot Nothing
If parentform.Parent IsNot Nothing Then parentform = _
parentform.Parent Else Exit While
End While
parentform.Width = Me.Status.uiImageWidth + (parentform.Width - _
parent.Width)
parentform.Height = Me.Status.uiImageHeight + (parentform.Height - _
parent.Height)
AddHandler parent.Resize, AddressOf ParentResizing
' Resize window to fit in picturebox
SetWindowPos(capwnd, HWND_BOTTOM, 0, 0, parent.ClientSize.Width, _
parent.ClientSize.Height, _
SWP_NOMOVE Or SWP_NOZORDER)
Else
' Error connecting to device close window
DestroyWindow(capwnd)
capwnd = 0
End If
If capwnd <> 0 Then active = True
Return active
End Function -----------------------------------
Betriebssystem: Schrott (Vista)
Entwicklungsumgebung: VS 2008
|