|
-
Jun 11th, 2026, 11:09 PM
#1
Thread Starter
Member
Webcam Access
VFW is old school and will not handle "modern" webcam resolution above 640 or access due to compression methods. Is there sample code to work with these newer Win and Webcams? Sample code for Quartz DirectShow or other available?
-
Jun 12th, 2026, 12:59 AM
#2
Re: Webcam Access
You could use the CameraCaptureUI Class.
The Windows.Media.Capture.CameraCaptureUI class provides a built-in, full-window camera user interface for Windows applications. It allows developers to quickly capture photos or videos without having to design custom UI elements or manage low-level camera hardware.
Since it's a WinRT class, it requires the WinRT TypeLib, everything should be pretty straightforward.
-
Jun 12th, 2026, 02:32 AM
#3
Re: Webcam Access
There's Quartz-based samples if you search the forum but that's nearly as old as VFW. Media Foundation would be the option if you didn't want to use RT. -Franky- made a sample if you don't mind DispCallFunc hell, or just tell an LLM to make a sample and it should only need minor changes to work with oleexp.tlb (or WDL in twinBASIC).
-
Jun 12th, 2026, 09:53 PM
#4
Re: Webcam Access
I've just included a Camera Capture project in the WinRT Sample Collection linked in the same thread. This project shows a live video preview from your webcam in a PictureBox. A ComboBox lists all available resolutions and video encoding properties supported by your camera and you can switch between them. The aptly named Snapshot button saves a JPG snapshot in the current folder.

The form is resizable and the live preview will be automatically resized accordingly. My Windows tablet has a crappy camera so that's what you see in the screenshot above. Professional webcams should support more advanced formats and video compression properties.
This is all it takes to initialize the live camera preview in Form_Load. The WinRT TypeLib makes everything very straight forward using the friendly and familiar VB6 syntax you are already accustomed with:
Code:
Private Sub Form_Load()
Dim DesktopWindowXamlSourceNative As IDesktopWindowXamlSourceNative, CaptureElement As ICaptureElement, MediaCaptureInitializationSettings As IMediaCaptureInitializationSettings, _
MediaCaptureVideoPreview As IMediaCaptureVideoPreview
Set m_DesktopWindowXamlSource = NewObject("DesktopWindowXamlSource"): Set DesktopWindowXamlSourceNative = m_DesktopWindowXamlSource: Set m_Await = New cAwait
With DesktopWindowXamlSourceNative
If .AttachToWindow(picCapture.hWnd) = S_OK Then
m_hWndIsland = .WindowHandle
Set CaptureElement = NewObject("CaptureElement"): Set m_DesktopWindowXamlSource.Content = CaptureElement
Set m_MediaCapture = NewObject("MediaCapture"): Set MediaCaptureInitializationSettings = NewObject("MediaCaptureInitializationSettings")
MediaCaptureInitializationSettings.StreamingCaptureMode = StreamingCaptureMode_Video: MediaCaptureInitializationSettings.PhotoCaptureSource = PhotoCaptureSource_VideoPreview
With m_Await
If .Await(m_MediaCapture.InitializeWithSettingsAsync(MediaCaptureInitializationSettings)) = AsyncStatus_Completed Then
Set CaptureElement.Source = m_MediaCapture: CaptureElement.Stretch = Stretch_UniformToFill: Set MediaCaptureVideoPreview = m_MediaCapture
If .Await(MediaCaptureVideoPreview.StartPreviewAsync) = AsyncStatus_Completed Then
Set m_ImageEncodingProperties = ImageEncodingPropertiesStatics.CreateJpeg: EnumerateSupportedResolutions m_MediaCapture.VideoDeviceController
End If
Else
MsgBox Hex$(.ErrorCode) & vbNewLine & .ErrorDescription, vbOKOnly + vbExclamation, App.Title
End If
End With
End If
End With
End Sub
-
Re: Webcam Access
I once wrote an example using Media Foundation, and it was quite a complex undertaking. If I ever had to write something like that again, I would switch to WinRT because it is much easier there. The only downside is that WinRT is only available from Windows 10 onwards, whereas Media Foundation can be used for this purpose starting with Windows 7.
-
Re: Webcam Access
 Originally Posted by Claude Prompt
Format this VB6 code with single statement/dim per line
Code:
Private Sub Form_Load()
Dim DesktopWindowXamlSourceNative As IDesktopWindowXamlSourceNative
Dim CaptureElement As ICaptureElement
Dim MediaCaptureInitializationSettings As IMediaCaptureInitializationSettings
Dim MediaCaptureVideoPreview As IMediaCaptureVideoPreview
Set m_DesktopWindowXamlSource = NewObject("DesktopWindowXamlSource")
Set DesktopWindowXamlSourceNative = m_DesktopWindowXamlSource
Set m_Await = New cAwait
With DesktopWindowXamlSourceNative
If .AttachToWindow(picCapture.hWnd) = S_OK Then
m_hWndIsland = .WindowHandle
Set CaptureElement = NewObject("CaptureElement")
Set m_DesktopWindowXamlSource.Content = CaptureElement
Set m_MediaCapture = NewObject("MediaCapture")
Set MediaCaptureInitializationSettings = NewObject("MediaCaptureInitializationSettings")
MediaCaptureInitializationSettings.StreamingCaptureMode = StreamingCaptureMode_Video
MediaCaptureInitializationSettings.PhotoCaptureSource = PhotoCaptureSource_VideoPreview
With m_Await
If .Await(m_MediaCapture.InitializeWithSettingsAsync(MediaCaptureInitializationSettings)) = AsyncStatus_Completed Then
Set CaptureElement.Source = m_MediaCapture
CaptureElement.Stretch = Stretch_UniformToFill
Set MediaCaptureVideoPreview = m_MediaCapture
If .Await(MediaCaptureVideoPreview.StartPreviewAsync) = AsyncStatus_Completed Then
Set m_ImageEncodingProperties = ImageEncodingPropertiesStatics.CreateJpeg
EnumerateSupportedResolutions m_MediaCapture.VideoDeviceController
End If
Else
MsgBox Hex$(.ErrorCode) & vbNewLine & .ErrorDescription, vbOKOnly + vbExclamation, App.Title
End If
End With
End If
End With
End Sub
-
Re: Webcam Access
A productive usage of tokens, now it runs twice as fast!
-
Re: Webcam Access
This 32 LOC snippet is not pretending to be a 23 LOC snippet and my horizontal scrollbar remains untouched :-))
I'm still strugging with these mouthful MediaCaptureInitializationSettings.StreamingCaptureMode = StreamingCaptureMode_Video assignments though. . .
cheers,
</wqw>
-
Re: Webcam Access
By default, the StreamingCaptureMode includes both Video and Audio. If Microphone access happens to be disallowed in your Privacy settings, this will result in Access Denied when trying to initialize the MediaCapture object.
The other mouthful, PhotoCaptureSource, specifies where you want to grab snapshots from. Fancier cameras have separate streams, VideoPreview stream and Photo stream (presumably higher quality).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|