Connect to Webcam Using Forth

How to use Forth to connect to a Webcam

Source code

\ working example of connecting to a webcam in SwiftForth
\ type in initcam to see it in action
LIBRARY avicap32.dll

FUNCTION: capCreateCaptureWindowA ( lpszWindowName dwStyle x y nWidth nHeight hwndParent nID – n )

variable webhandle
1034 CONSTANT WM_CAP_DRIVER_CONNECT
1076 CONSTANT WM_CAP_SET_PREVIEWRATE
1074 CONSTANT WM_CAP_SET_PREVIEW

: sethandle ( – h ) webhandle ! webhandle @ ;
: setsize ( – bool ) z" Forth Cam" WS_VISIBLE 0 0 300 300 0 0 capCreateCaptureWindowA sethandle ;
: webconnect ( – bool ) webhandle @ WM_CAP_DRIVER_CONNECT 0 0 SendMessage ;
: setrate ( – bool ) webhandle @ WM_CAP_SET_PREVIEWRATE 500 0 SendMessage ;
: runcam ( – bool ) webhandle @ WM_CAP_SET_PREVIEW true 0 SendMessage ;
: initcam ( – bool ) setsize 0= if ." Error" else
webconnect drop
setrate drop
runcam drop
then ;