TWebcam
Source: source/classes/twebcam.prg
Hierarchy: TWebcam → TControl
TWebcam provides live webcam preview and capture functionality using the Video for Windows (VFW) API. It is a visual control that displays the camera feed within a FiveWin window and supports snapshot capture, video format dialogs, and video source configuration.
WEBCAM Command
@ nRow, nCol WEBCAM oCam OF oWnd SIZE nW, nH INIT lInit
Key DATA Members
| DATA | Type | Default | Description |
|---|---|---|---|
hWebcam | Numeric | Handle to the VFW capture window | |
cName | Character | Webcam driver description | |
cVersion | Character | Webcam driver version string | |
nRateRefresh | Numeric | 66 | Preview refresh rate in milliseconds |
isScale | Logical | .T. | Scale preview to control size (640x480 when disabled) |
isConnected | Logical | .F. | Whether preview is currently active |
Methods
| Method | Description |
|---|---|
New( oWnd, nTop, nLeft, nWidth, nHeight, lInit, lAdjust, nRate, bError ) | Constructor. Creates the VFW capture window and optionally starts preview. |
Initialize() | Connect the webcam driver and start the live preview. |
Finalize() | Disconnect the webcam driver and stop the preview. |
SaveFile( cFileName ) | Capture the current frame to a BMP file. Defaults to a timestamp-based filename. |
VideoControl() | Open the video source property dialog (brightness, contrast, etc.). |
VideoFormat() | Open the video format dialog (resolution, color depth). |
StartCapture( cFile ) | Begin streaming capture to a video file. |
StopCapture() | Stop any ongoing video capture. |
GetWidth() | Return the current preview image width in pixels. |
GetHeight() | Return the current preview image height in pixels. |
SetRate( nRate ) | Set the preview refresh rate in milliseconds. |
Example: Live Preview with Capture
#include "FiveWin.ch"
function Main()
local oWnd, oCam, lInit := .T.
DEFINE WINDOW oWnd TITLE "Webcam Capture" ;
SIZE 800, 600
@ 10, 10 WEBCAM oCam OF oWnd SIZE 640, 480 INIT lInit
@ 500, 10 BUTTON "&Snapshot" SIZE 60, 25 ;
ACTION oCam:SaveFile( "snap.bmp" )
@ 500, 80 BUTTON "&Format" SIZE 60, 25 ;
ACTION oCam:VideoFormat()
@ 500, 150 BUTTON "&Controls" SIZE 60, 25 ;
ACTION oCam:VideoControl()
@ 500, 220 BUTTON "&Close" SIZE 60, 25 ;
ACTION oWnd:End()
ACTIVATE WINDOW oWnd ;
ON INIT oCam:Initialize() ;
VALID ( oCam:Finalize(), .T. )
return nil
Notes
- TWebcam relies on the legacy VFW (Video for Windows) API. It works on all 32-bit and 64-bit Windows versions through the
avicap32.dllandmsvfw32.dllsystem libraries. - The control must be created before the parent window is activated; use the
INITclause or callInitialize()manually fromON INIT. - Snapshots are saved as 24-bit BMP files by default.
- Use
GetVideoCapDriver()(a utility function in twebcam.prg) to enumerate available webcam devices. - Error events are routed through the
bErrorcodeblock. The default handler shows aMsgAlertdialog.