Mit dem Code hier müsste es gehen. Du schickst per capCreateCaptureWindow die Videonachricht an dein Fenster (Webcam an) und kannst die Webcam wieder ausschalten:
Public videoHandle As IntPtr
Private Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As _
IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As _
Integer) As Integer
Const EM_LINEFROMCHAR As Integer = &HC9
Const EM_LINEINDEX As Integer = &HBB
Private Declare Auto Function capCreateCaptureWindow 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 _
Integer, ByVal hWndParent As IntPtr, ByVal nID As Integer) As IntPtr
Private Const WS_CHILD As Integer = &H40000000
Private Const WS_VISIBLE As Integer = &H10000000
Private Const WM_USER As Short = &H400S
Private Const WM_CAP_START As Short = &H400S
Private Const WM_CAP_EDIT_COPY As Integer = (WM_CAP_START + 30)
Private Const WM_CAP_DRIVER_CONNECT As Integer = (WM_CAP_START + 10)
Private Const WM_CAP_SET_PREVIEWRATE As Integer = (WM_CAP_START + 52)
Private Const WM_CAP_SET_OVERLAY As Integer = (WM_CAP_START + 51)
Private Const WM_CAP_SET_PREVIEW As Integer = (WM_CAP_START + 50)
Private Const WM_CAP_DRIVER_DISCONNECT As Integer = (WM_CAP_START + 11)
Public Function CreateCaptureWindow(ByRef hWndParent As IntPtr, Optional _
ByRef x As Integer = 0, Optional ByRef y As Integer = 0, Optional ByRef _
nWidth As Integer = 320, Optional ByRef nHeight As Integer = 240, Optional _
ByRef nCameraID As Integer = 0) As IntPtr
Dim previewHandle As IntPtr
previewHandle = capCreateCaptureWindow("Video", WS_CHILD + WS_VISIBLE, _
x, y, nWidth, nHeight, hWndParent, 1)
SendMessage(previewHandle, WM_CAP_DRIVER_CONNECT, nCameraID, 0)
SendMessage(previewHandle, WM_CAP_SET_PREVIEWRATE, 30, 0)
SendMessage(previewHandle, WM_CAP_SET_OVERLAY, 1, 0)
SendMessage(previewHandle, WM_CAP_SET_PREVIEW, 1, 0)
Return previewHandle
End Function
'Webcam anschalten (Button1):
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
videoHandle = Me.CreateCaptureWindow(New IntPtr(400))
End Sub
Public Sub Disconnect(ByRef nCaptureHandle As IntPtr, Optional ByRef _
nCameraID As Integer = 0)
SendMessage(nCaptureHandle, WM_CAP_DRIVER_DISCONNECT, nCameraID, 0)
End Sub
'GANZ WICHTIG: Beim Beenden muss die WebCam wieder freigegeben werden!
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As _
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Disconnect(videoHandle)
End Sub
'Webcam ausschalten (Button2):
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button2.Click
Disconnect(videoHandle)
End Sub ______________________________________
www.fk-freeware.de.vu |