library VideoCap;{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }uses ShareMem, SysUtils, ExtCtrls, ComCtrls, Classes, Dialogs, windows, VFW in 'vfw.pas'; /// var ghCapWnd:HWND; {$R *.res} function capCreateCaptureWindowA(lpszwindowname:pchar;dstyle:longint;x:integer;y:integer;nwidth:integer; Nheight:integer;parentwin:HWND;nid:integer):HWND; stdcall external 'AVICAP32.dll'; /// function StartCap(VideoWind:TPanel):boolean;export; begin StartCap := false; ghCapWnd:=CapCreateCaptureWindowA(Pchar('QingHuntSoft'), WS_CHILD or WS_VISIBLE, 0, 0, VideoWind.Width, VideoWind.Height, VideoWind.Handle, 10); if ghCapWnd<>0 then try SendMessage(ghcapwnd,WM_CAP_DRIVER_CONNECT,0,0); sendmessage(ghcapwnd,WM_CAP_SET_SCALE,1,1); sendmessage(ghcapwnd,WM_CAP_SET_PREVIEWRATE,1,1); sendmessage(ghcapwnd,WM_CAP_SET_OVERLAY,1,0); sendmessage(ghcapwnd,WM_CAP_SET_PREVIEW,1,1); StartCap := true; Except StartCap := false; Abort; end; end; /// procedure StopCap;export; begin sendmessage(ghcapwnd,WM_CAP_DRIVER_DISCONNECT,0,0); end; /// procedure SaveCap(SavePath:string);export; var Year, Month, Day, Hour, Min, Sec, MSec: Word; CapParms: PCaptureParms; Present: TDateTime; PathStr,MM,DD,HH:string; CapFileName:String; begin Present:=now; DecodeDate(Present,Year,Month,Day); DecodeTime(Present, Hour, Min, Sec, MSec); if Month<10 then MM:=inttostr(0)+inttostr(Month) else MM:=inttostr(month); if Day<10 then DD:=inttoStr(0)+inttostr(day) else DD:=inttostr(day) ; if Hour<10 then HH:=inttostr(0)+inttostr(Hour) else HH:=inttostr(Hour); PathStr:=SavePath+'\'+MM+'月'+DD+'日'; if Not DireCtoryExists(PathStr) then ForceDirectories(PathStr); CapFileName:=DD+'-'+HH+'.Avi'; if GhcapWnd<>0 then begin CapCaptureGetSetup(ghCapWnd,CapParms,sizeof(TCAPTUREPARMS)); CapParms.fLimitEnabled := false; CapParms.fYield := TRUE; CapParms.vKeyAbort := VK_ESCAPE; CapParms.fAbortLeftMouse := FALSE; CapParms.fAbortRightMouse := FALSE; CapCaptureSetSetup(ghCapWnd,CapParms,sizeof(TCAPTUREPARMS)); sendmessage(ghcapwnd,WM_CAP_FILE_SET_CAPTURE_FILE,0,Longint(Pchar(PathStr+'\'+Capfilename))); sendmessage(ghcapwnd,WM_CAP_SEQUENCE,0,0); end; end; /// procedure StopSaveCap;export; begin sendmessage(ghcapwnd,WM_CAP_STOP,0,0); end; /// procedure SaveCapImage(SaveDialog:TSaveDialog);export; begin if ghCapWnd<>0 then begin SaveDialog.DefaultExt:='bmp'; Savedialog.Filter:='Bitmap Files (*.Bmp)|*.bmp'; if SaveDialog.Execute then Sendmessage(ghCapWnd,WM_CAP_FILE_SAVEDIB,0,Longint(Pchar(Savedialog.FileName))); end; end; /// exports StartCap, StopCap, SaveCap, StopSaveCap, SaveCapImage; begin end.
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
ShareMem,
SysUtils,
ExtCtrls,
ComCtrls,
Classes,
Dialogs,
windows,
VFW in 'vfw.pas';
///
var
ghCapWnd:HWND;
{$R *.res}
function capCreateCaptureWindowA(lpszwindowname:pchar;dstyle:longint;x:integer;y:integer;nwidth:integer;
Nheight:integer;parentwin:HWND;nid:integer):HWND; stdcall external 'AVICAP32.dll';
///
function StartCap(VideoWind:TPanel):boolean;export;
begin
StartCap := false;
ghCapWnd:=CapCreateCaptureWindowA(Pchar('QingHuntSoft'),
WS_CHILD or WS_VISIBLE,
0,
0,
VideoWind.Width,
VideoWind.Height,
VideoWind.Handle,
10);
if ghCapWnd<>0 then
try
SendMessage(ghcapwnd,WM_CAP_DRIVER_CONNECT,0,0);
sendmessage(ghcapwnd,WM_CAP_SET_SCALE,1,1);
sendmessage(ghcapwnd,WM_CAP_SET_PREVIEWRATE,1,1);
sendmessage(ghcapwnd,WM_CAP_SET_OVERLAY,1,0);
sendmessage(ghcapwnd,WM_CAP_SET_PREVIEW,1,1);
StartCap := true;
Except
StartCap := false;
Abort;
end;
end;
///
procedure StopCap;export;
begin
sendmessage(ghcapwnd,WM_CAP_DRIVER_DISCONNECT,0,0);
end;
///
procedure SaveCap(SavePath:string);export;
var
Year, Month, Day, Hour, Min, Sec, MSec: Word;
CapParms: PCaptureParms;
Present: TDateTime;
PathStr,MM,DD,HH:string;
CapFileName:String;
begin
Present:=now;
DecodeDate(Present,Year,Month,Day);
DecodeTime(Present, Hour, Min, Sec, MSec);
if Month<10 then MM:=inttostr(0)+inttostr(Month) else MM:=inttostr(month);
if Day<10 then DD:=inttoStr(0)+inttostr(day) else DD:=inttostr(day) ;
if Hour<10 then HH:=inttostr(0)+inttostr(Hour) else HH:=inttostr(Hour);
PathStr:=SavePath+'\'+MM+'月'+DD+'日';
if Not DireCtoryExists(PathStr) then ForceDirectories(PathStr);
CapFileName:=DD+'-'+HH+'.Avi';
if GhcapWnd<>0 then
begin
CapCaptureGetSetup(ghCapWnd,CapParms,sizeof(TCAPTUREPARMS));
CapParms.fLimitEnabled := false;
CapParms.fYield := TRUE;
CapParms.vKeyAbort := VK_ESCAPE;
CapParms.fAbortLeftMouse := FALSE;
CapParms.fAbortRightMouse := FALSE;
CapCaptureSetSetup(ghCapWnd,CapParms,sizeof(TCAPTUREPARMS));
sendmessage(ghcapwnd,WM_CAP_FILE_SET_CAPTURE_FILE,0,Longint(Pchar(PathStr+'\'+Capfilename)));
sendmessage(ghcapwnd,WM_CAP_SEQUENCE,0,0);
end;
end;
///
procedure StopSaveCap;export;
begin
sendmessage(ghcapwnd,WM_CAP_STOP,0,0);
end;
///
procedure SaveCapImage(SaveDialog:TSaveDialog);export;
begin
if ghCapWnd<>0 then
begin
SaveDialog.DefaultExt:='bmp';
Savedialog.Filter:='Bitmap Files (*.Bmp)|*.bmp';
if SaveDialog.Execute then
Sendmessage(ghCapWnd,WM_CAP_FILE_SAVEDIB,0,Longint(Pchar(Savedialog.FileName)));
end;
end;
///
exports
StartCap,
StopCap,
SaveCap,
StopSaveCap,
SaveCapImage;
begin
end.
但是拍照的时候没做好,但是原理是正确的
都是通过发送消息实现的
你把上面代码直接用到Form中就可以了
不过不要忘记Uses
AviCap,Ole2,Vfw 这3个文件
至于哪来
就要你自己去找了