VFP call the API to control the USB camera, or video camera to achieve

* - premise: VFP7.0 above; Windows 2K and above
* - Control: AVICAP32.DLL

* - Definition: Load event into the main or general form (set) in the
Public WM_CAP_DRIVER_DISCONNECT
Public hwndc, WM_CAP_SAVEDIB, WM_CAP_FILE_SET_CAPTURE_FILEA, WM_CAP_SEQUENCE, WM_CAP_STOP
the Declare Integer capCreateCaptureWindowA the In "Avicap32.dll" lpszWindowName String, Integer the dwStyle,;
Integer X, Integer the Y, Integer nWidth, Integer nHeight, Integer ParentWin, Integer NID
the Declare Integer the SendMessage the In "user32" Integer the HWnd, Integer wMsg, Integer wpar1, Integer wpar2
the Declare Integer the SendMessage the In "user32" of As SendMessageA Integer the HWnd, Integer wMsg, Integer wpar1, String wpar2

*--显示:可以放到按钮或表单(集)的Init事件中
WM_USER = 1024
WM_CAP_START = WM_USER
WM_CAP_STOP = WM_CAP_START + 68
WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
WM_CAP_SAVEDIB = WM_CAP_START + 25
WM_CAP_GRAB_FRAME = WM_CAP_START + 60
WM_CAP_SEQUENCE = WM_CAP_START + 62
WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20
WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63
WM_CAP_SET_OVERLAY =WM_CAP_START+ 51
WM_CAP_SET_PREVIEW =WM_CAP_START+ 50
WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6
WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2
WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3
WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5
= + 53 is WM_CAP_START WM_CAP_SET_SCALE
WM_CAP_SET_PREVIEWRATE = + 52 is WM_CAP_START
* parameter is defined in the third and fourth display position, 5,6 parameter is defined display size.
= capCreateCaptureWindowA hWndC ( 'My Own Capture the Window', 1342177280,0,0,320,240, Thisform.HWnd, 0)
the If hWndC <> 0
the SendMessage (hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0)
the SendMessage (hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0)
the SendMessage ( hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0)
the SendMessage (hWndC, WM_CAP_DRIVER_CONNECT, 0, 0)
the SendMessage (hWndC, WM_CAP_SET_SCALE,. 1, 0)
the SendMessage (hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0)
the SendMessage (hWndC, WM_CAP_SET_OVERLAY,. 1, 0)
the SendMessage ( hWndC, WM_CAP_SET_PREVIEW,. 1, 0)
* THISFORM.ACTIVATE
Endif

* - turn off the display:
the SendMessage (hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0)
hWndC = 0

* - Save the image:
* - can not control the file size generated by the camera itself because it is the default, but be down-scaled display is available when the Image control.
getfile = SS ( "BMP; Jpg")
! Empty the If (SS)
SendMessageA (hWndC, WM_CAP_SAVEDIB, 0, SS)
Endif

*--录像:
ss = Getfile("avi")
If !Empty(ss)
SendMessageA(hWndC,WM_CAP_FILE_SET_CAPTURE_FILEA,0,ss)
SendMessageA(hWndC, WM_CAP_SEQUENCE, 0, 0)
This.Enabled=.F.
Thisform.MousePointer= 0
Thisform.停止录像按钮.Enabled=.T.
Endif

* - Stop recording:
SendMessage (hWndC, WM_CAP_STOP, 0, 0)
Thisform start recording button = .T .Enabled..
This.Enabled = .F.

Guess you like

Origin www.cnblogs.com/hnllhq/p/12286782.html