autodefine "off" $include "windowssdk.inc" $include "commctrl.inc" $include "vfw2.inc" $include "shlwapi.inc" enum CTLID IDC_ADJUST = 1000 IDC_SAVEBITMAP IDC_COPY IDC_VIDEOCOMPRESSION IDC_VIDEOSOURCE IDC_VIDEOFORMAT IDC_VIDEODISPLAY IDC_CAMERA IDC_CAPPARENT IDC_FRAMERATE IDC_FRAMERATEINFO IDC_PREVIEW endenum DIALOG d1 UINT hWndCap1 CREATEDIALOG d1,0,0,382,330,0x80CB0080,0,"Caption",&handler CONTROL d1,@GROUPBOX,"Camera",7,9,270,309,0x50000007,IDC_CAMERA CONTROL d1,@COMBOBOX,"",14,25,256,80,0x50A10642,IDC_CAMERA CONTROL d1,@SYSBUTTON,"Adjust",14,286,85,24,0x50010000,IDC_ADJUST CONTROL d1,@SYSBUTTON,"Copy",105,286,85,24,0x50010000,IDC_COPY CONTROL d1,@SYSBUTTON,"Save",196,286,75,24,0x50010000,IDC_SAVEBITMAP CONTROL d1,@STATIC,"",14,50,256,226,0x50800000,IDC_CAPPARENT /*parent window for webcam*/ CONTROL d1,@BUTTON,"Cancel",27,313,60,16,0x40080000,IDCANCEL CONTROL d1,@STATIC,"Framerate",290,6,80,14,0x5000010B,IDC_FRAMERATEINFO CONTROLEX d1,"msctls_trackbar32","",292,22,80,20,@TABSTOP|TBS_AUTOTICKS|TBS_TOOLTIPS,0,IDC_FRAMERATE CONTROL d1,@CHECKBOX,"Preview",298,300,70,15,0x50010003,IDC_PREVIEW CONTROL d1,@SYSBUTTON,"Video source",279,221,101,22,0x50010000,IDC_VIDEOSOURCE CONTROL d1,@SYSBUTTON,"Video format",279,243,101,22,0x50010000,IDC_VIDEOFORMAT CONTROL d1,@SYSBUTTON,"Video display",279,266,101,22,0x50010000,IDC_VIDEODISPLAY CONTROL d1,@SYSBUTTON,"Video compression",279,199,101,22,0x50010000,IDC_VIDEOCOMPRESSION showdialog d1 waituntil d1=0 sub handler(),INT STRING name, descr INT L,T,W,H INT a select @MESSAGE case @IDINITDIALOG CenterWindow d1 SetControlColor d1, IDC_CAPPARENT, 0, 0 SetState d1, IDC_PREVIEW, TRUE Addstring d1, IDC_CAMERA, "None" SetControlColor d1, IDC_FRAMERATE, 0, GetSysColor(15) SendMessage d1, TBM_SETRANGE, TRUE, 50<<16|1, IDC_FRAMERATE SendMessage d1, TBM_SETTICFREQ, 8, 0, IDC_FRAMERATE SendMessage d1, TBM_SETPOS, TRUE, 15, IDC_FRAMERATE ' enum available capture drivers for a = 0 to 9 if capGetDriverDescription(a, name, 255, descr, 255) = 0 then breakfor addstring d1, IDC_CAMERA, name next a ' select the first driver setselected d1, IDC_CAMERA, 0+(a>0) ' create preview window getsize(d1, L,T,W,H,IDC_CAPPARENT) hWndCap1 = capCreateCaptureWindow("capture 1", 0x50000000, 0,0,W,H, getcontrolhandle(d1, IDC_CAPPARENT), 20) ' and run capStart() case @IDCONTROL select @CONTROLID case IDC_CAMERA if @NOTIFYCODE = @CBNSELCHANGE capStart(getselected(d1, IDC_CAMERA)) endif case @IDCANCEL sendmessage d1, @IDCANCEL, 0,0 endselect if @notifycode = 0 select @CONTROLID case IDC_PREVIEW : capSerPreview() case IDC_COPY : sendmessage hWndCap1, WM_CAP_EDIT_COPY, 0, 0 case IDC_SAVEBITMAP : capSaveFrame() case IDC_VIDEOCOMPRESSION: sendmessage hWndCap1, WM_CAP_DLG_VIDEOCOMPRESSION, 0, 0 case IDC_VIDEOSOURCE : sendmessage hWndCap1, WM_CAP_DLG_VIDEOSOURCE, 0, 0 case IDC_VIDEOFORMAT : sendmessage hWndCap1, WM_CAP_DLG_VIDEOFORMAT, 0, 0 case IDC_VIDEODISPLAY : sendmessage hWndCap1, WM_CAP_DLG_VIDEODISPLAY, 0, 0 endselect endif case @IDCLOSEWINDOW case& @IDCANCEL capDisonnect() closedialog d1 case @IDHSCROLL a=@LPARAM&0xFFFF if a then capSetFramerate(a) case @IDMOVE capSetFramerate(0) starttimer d1, 500, 1000 case @IDTIMER if @WPARAM=1000 stoptimer d1, 1000 capSetFramerate() endif endselect return 0 endsub ' index 1-10 or 0 if only stop sub capStart(opt index=1:int) CAPDRIVERCAPS cdc if hWndCap1=0 then return capDisonnect() if index=0 then return index-- capConnect(index) capSetFramerate() SendMessage hWndCap1, WM_CAP_SET_OVERLAY, TRUE, 0 capSetScale(FALSE) capSerPreview() ' setup controls EnableControl d1, IDC_VIDEOSOURCE, FALSE EnableControl d1, IDC_VIDEOFORMAT, FALSE EnableControl d1, IDC_VIDEODISPLAY, FALSE if SendMessage(hWndCap1, WM_CAP_DRIVER_GET_CAPS, 44, &cdc) EnableControl d1, IDC_VIDEOSOURCE, cdc.fHasDlgVideoSource EnableControl d1, IDC_VIDEOFORMAT, cdc.fHasDlgVideoFormat EnableControl d1, IDC_VIDEODISPLAY, cdc.fHasDlgVideoDisplay endif endsub sub capSetFramerate(opt frq_hz=-1:int) INT rate if hWndCap1=0 then return if frq_hz = -1 frq_hz = sendmessage(d1, TBM_GETPOS,0,0,IDC_FRAMERATE) endif rate=0 if frq_hz then rate = 1000/frq_hz setcaption d1, str$(rate)+STR$(frq_hz) SetControlText d1, IDC_FRAMERATEINFO, using("Framerate ##Hz ", frq_hz) SendMessage hWndCap1, WM_CAP_SET_PREVIEWRATE, rate, 0 endsub sub capConnect(index:int) SendMessage hWndCap1, WM_CAP_DRIVER_CONNECT, index, 0 endsub sub capDisonnect SendMessage hWndCap1, WM_CAP_DRIVER_DISCONNECT, 0, 0 endsub 'enables or disables scaling of the preview video images. If scaling is enabled, 'the captured video frame is stretched to the dimensions of the capture window sub capSetScale(enable:int) SendMessage hWndCap1, WM_CAP_SET_SCALE, enable, 0 endsub sub capSerPreview(opt enable=-1:int) if enable=-1 enable=getstate(d1, IDC_PREVIEW) endif SendMessage hWndCap1, WM_CAP_SET_PREVIEW, enable, 0 endsub sub capSaveFrame ISTRING path[300] INT cnt POINTER path_end IF hWndCap1=0 then return path = GetStartPath path_end = &path + len(path) for cnt = 1 to 0x7FFFFFFF wsprintf(path_end, "%.5d.bmp", cnt) if PathFileExists(path) = FALSE if SendMessage(hWndCap1, WM_CAP_FILE_SAVEDIB, 0, &path) SetCaption d1, "Saved as " + *path_end else SetCaption d1, "Failed to save as " + *path_end DeleteFile path endif BreakFor endif next cnt endsub