VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 6375 ClientLeft = 60 ClientTop = 345 ClientWidth = 9210 LinkTopic = "Form1" ScaleHeight = 6375 ScaleWidth = 9210 StartUpPosition = 3 'Windows Default Begin VB.TextBox txtLog Height = 5055 Left = 5940 MultiLine = -1 'True TabIndex = 4 Top = 900 Width = 2895 End Begin VB.ComboBox cmbDeviceL Height = 315 Left = 60 Style = 2 'Dropdown List TabIndex = 3 Top = 660 Width = 4695 End Begin VB.PictureBox picOutput Height = 3975 Left = 60 ScaleHeight = 3915 ScaleWidth = 5295 TabIndex = 2 Top = 1020 Width = 5355 End Begin VB.Timer tmrMain Interval = 1000 Left = 3600 Top = 240 End Begin VB.CommandButton cmdStop Caption = "Stop" Enabled = 0 'False Height = 255 Left = 1440 TabIndex = 1 Top = 360 Width = 735 End Begin VB.CommandButton cmdStart Caption = "start" Height = 255 Left = 660 TabIndex = 0 Top = 360 Width = 735 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private 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 Const CONNECT As Long = 1034 Const DISCONNECT As Long = 1035 Const GET_FRAME As Long = 1084 Const GET_NAME As Long = &H412 Const COPY As Long = 1054 Public mCapHwnd As Long Private Sub cmdStart_Click() cmdStart.Enabled = False cmdStop.Enabled = True 'Setup a capture window (You can replace "WebcamCapture" with watever you want) mCapHwnd = capCreateCaptureWindow("WebcamCapture", 0, 0, 0, 320, 240, Me.hwnd, 0) 'Connect to capture device DoEvents: SendMessage mCapHwnd, CONNECT, 0, 0 tmrMain.Enabled = True End Sub Private Sub cmdStop_Click() cmdStart.Enabled = True cmdStop.Enabled = False tmrMain.Enabled = False 'Make sure to disconnect from capture source!!! DoEvents: SendMessage mCapHwnd, DISCONNECT, 0, 0 End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If cmdStop.Enabled = False Then 'Make sure to disconnect from capture source - if it is connected upon termination the program can become unstable DoEvents: SendMessage mCapHwnd, DISCONNECT, 0, 0 End If End Sub Private Sub tmrMain_Timer() On Error Resume Next 'Get Current Frame SendMessage mCapHwnd, GET_FRAME, 0, 0 'Copy Current Frame to ClipBoard SendMessage mCapHwnd, COPY, 0, 0 'Put ClipBoard's Data to picOutput picOutput.Picture = Clipboard.GetData 'Clear ClipBoard Clipboard.Clear End Sub Private Sub Form_Load() Dim val, val2, i For i = 0 To 9 val = SendMessage(mCapHwnd, CONNECT, i, 0) val2 = SendMessage(mCapHwnd, GET_NAME, i, 0) txtLog.Text = txtLog.Text & i & ":" & val & "=" & val2 & vbNewLine Next End Sub