WebCam dialog

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
2 posts Page 1 of 1
Contributors
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

WebCam dialog
M1z23R
How could you auto choose webcam device, or auto respond to this dialog ?
Image
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: WebCam dialog
mandai
I have found there are a few ways to discover/communicate with this window.

If you just want to detect the window and automatically click the OK button you could use this:
Code: Select all
    <DllImport("user32.dll")> Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll")> Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("user32.dll")> Shared Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
    End Function

    Const BM_CLICK As UInteger = &HF5

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

        Dim dialog As IntPtr = FindWindow(Nothing, "Video Source")

        If dialog <> IntPtr.Zero Then

            Timer1.Stop()

            Dim btnOk As IntPtr = FindWindowEx(dialog, IntPtr.Zero, Nothing, "OK")
            SendMessage(btnOk, BM_CLICK, IntPtr.Zero, IntPtr.Zero)

        End If
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub
If you want to get the item count and set the ComboBox index you could use something like this:
Code: Select all
    Const CB_GETCOUNT As UInteger = &H146
    Const CB_SETCURSEL As UInteger = &H14E
...
Code: Select all
            Dim tabPage As IntPtr = FindWindowEx(dialog, IntPtr.Zero, Nothing, "Capture Source")

            Dim comboBox As IntPtr = FindWindowEx(tabPage, IntPtr.Zero, "ComboBox", Nothing)

            'get the number of devices
            Dim deviceCount As IntPtr = SendMessage(comboBox, CB_GETCOUNT, IntPtr.Zero, IntPtr.Zero)
            MsgBox(deviceCount)

            'set the device index
            Dim newindex As Integer = -1 'this would invalidate the current index
            Dim ptrNewindex As IntPtr = New IntPtr(newindex)
            SendMessage(comboBox, CB_SETCURSEL, ptrNewindex, IntPtr.Zero)
2 posts Page 1 of 1
Return to “Coding Help & Support”