绝对原创, 自己封装, 方便使用.
使用的是TSCRec1.dll.
View Code
// H to Pas Converter Ver.1.20.1.47 by K.Kumaki // Date : 31 Mar 2012 // Source : TSCRecApi.h (17 Feb 2003) unit TSCRecApi; {$X+}{$Z2}{$A8} interface uses Windows, Forms; const Dll = 'TSCRec1.dll'; // General Function return values CAMREC_SUCCESS = TRUE; // General error - success CAMREC_FAILED = FALSE; // General error - failure CAMREC_FAILED_NUMERIC = -1; // General error - failure on a function not returning a BOOL type HCAMREC = THandle; // capture object handle // Video callback parameters p_camVideoCallbackParams = ^camVideoCallbackParams; camVideoCallbackParams = record hFrameDC : HDC; hBitmap : HBITMAP; hPalette : HPALETTE; lpbi : PBitmapInfo; pvBits : Pointer; CursorPoint : TPoint; hCursor : HCURSOR; end; type camInput = ( cinScreen = 0, cinWindow = 1, cinRegion = 2 ); camOutput = ( coutNone = 0, coutFile = 1 ); camState = ( cstStarting = $01, cstStarted = $02, cstStopping = $04, cstStopped = $08, cstPaused = $10, cstRendering = $11, cstAll = $1 ); camAudioSource = ( casNone = 0, casWaveIn = 1, casApplication = 2 ); camFrameRateBase = ( cfrbSeconds = 1, cfrbMinutes = 60, cfrbHours = 3600 ); camCaptureMode = ( ccmNormal = 0, ccmQuick = 1, ccmEventStreaming = 2, ccmEventSingleFrame = 3 ); camAviInterleaveMode = ( cimNone = 0, cimInterleaveByFrames = 1, cimInterleaveBySeconds = 2 ); camPropertyType = ( cptCapture = $01, cptFile = $02, cptAvi = $04, cptAll = $07 ); // CamGetLastError values camError = ( cerrNone = $0000, cerrInvalidState = $0001, cerrInvalidParam = $0002, cerrInvalidTempFolder = $0003, cerrInvalidOutputFile = $0004, cerrInvalidInput = $0005, cerrNoVideoCallback = $0006, cerrNoWaveInDevice = $0007, cerrResourceAllocationFailed = $0008, cerrRenderingFailed = $0009, cerrVideoFileOpenFailed = $000A, cerrVideoWriteFailed = $000B, cerrAudioConversionFailed = $000C, cerrAudioFormatInvalid = $000D, cerrAudioFormatUnavailable = $000E, cerrAudioDeviceOpenFailed = $000, cerrAudioDeviceStartFailed = $0010, cerrAudioFileOpenFailed = $0011, cerrAudioWriteFailed = $0012, cerrAviUnsupported = $0013 ); ///////////////////////////////////////////////////////////////////// // Function Prototypes // Callback functions CAMSTATECHANGEPROC = function (State: camState; var pData): BOOL; stdcall; CAMERRORPROC = function (Error: camError; var pData): BOOL; stdcall; CAMVIDEOPROC = function (var pCallbackParams: camVideoCallbackParams; var pData): BOOL; stdcall; // Capture object creation function CamCreateCaptureA(const szLicense: PChar): HCAMREC; stdcall; external Dll; function CamCreateCaptureW(szLicense: PWChar): HCAMREC; stdcall; external Dll; function CamDestroyCapture(hCapture: HCAMREC): BOOL; stdcall; external Dll; // Capture Methods function CamStartCapture(hCapture: HCAMREC): BOOL; stdcall; external Dll; function CamStopCapture(hCapture: HCAMREC): BOOL; stdcall; external Dll; function CamPauseCapture(hCapture: HCAMREC): BOOL; stdcall; external Dll; function CamResumeCapture(hCapture: HCAMREC): BOOL; stdcall; external Dll; function CamAbortCapture(hCapture: HCAMREC): BOOL; stdcall; external Dll; // Advanced Capture Methods function CamCaptureEvent(hCapture: HCAMREC): BOOL; stdcall; external Dll; function CamAppAudio(hCapture: HCAMREC; dwNumberOfSamples: DWORD; dwBufferLength: DWORD; lpBuffer: Pointer): BOOL; stdcall; external Dll; function CamPaletteChanged(hCapture: HCAMREC): BOOL; stdcall; external Dll; // Capture Properties function CamSetInput(hCapture: HCAMREC; Input: camInput; hWnd: HWND; pRect: PRect): BOOL; stdcall; external Dll; function CamGetInput(hCapture: HCAMREC; var pInput: camInput; var phWnd: HWND; pRect: PRect): BOOL; stdcall; external Dll; function CamSetOutput(hCapture: HCAMREC; Output: camOutput): BOOL; stdcall; external Dll; function CamGetOutput(hCapture: HCAMREC; var pOutput: camOutput): BOOL; stdcall; external Dll; function CamSetCaptureFrameRate(hCapture: HCAMREC; dwRate: DWORD; dwScale: DWORD; Base: camFrameRateBase): BOOL; stdcall; external Dll; function CamGetCaptureFrameRate(hCapture: HCAMREC; var pdwRate: DWORD; var pdwScale: DWORD; var pdwBase: camFrameRateBase): BOOL; stdcall; external Dll; function CamSetRecordCursor(hCapture: HCAMREC; bEnable: BOOL): BOOL; stdcall; external Dll; function CamGetRecordCursor(hCapture: HCAMREC; var pbEnable: BOOL): BOOL; stdcall; external Dll; function CamSetAudioSource(hCapture: HCAMREC; Source: camAudioSource): BOOL; stdcall; external Dll; function CamGetAudioSource(hCapture: HCAMREC; var pSource: camAudioSource): BOOL; stdcall; external Dll; function CamSetAudioCaptureDevice(hCapture: HCAMREC; dwAudioDeviceID: DWORD): BOOL; stdcall; external Dll; function CamGetAudioCaptureDevice(hCapture: HCAMREC; var pdwAudioDeviceID: DWORD): BOOL; stdcall; external Dll; // Advanced Capture Properties function CamSetOptimalCaptureFrameRate(hCapture: HCAMREC; bEnable: BOOL): BOOL; stdcall; external Dll; function CamGetOptimalCaptureFrameRate(hCapture: HCAMREC; var pbEnable: BOOL): BOOL; stdcall; external Dll; function CamSetHideCaptureRectangle(hCapture: HCAMREC; bEnable: BOOL): BOOL; stdcall; external Dll; function CamGetHideCaptureRectangle(hCapture: HCAMREC; var pbEnable: BOOL): BOOL; stdcall; external Dll; function CamSetRoundFrameSize(hCapture: HCAMREC; dwPixelBoundry: DWORD): BOOL; stdcall; external Dll; function CamGetRoundFrameSize(hCapture: HCAMREC; var pdwPixelBoundry: DWORD): BOOL; stdcall; external Dll; function CamSetBoostPriority(hCapture: HCAMREC; bEnable: BOOL): BOOL; stdcall; external Dll; function CamGetBoostPriority(hCapture: HCAMREC; var pbEnable: BOOL): BOOL; stdcall; external Dll; function CamSetCaptureMode(hCapture: HCAMREC; Mode: camCaptureMode): BOOL; stdcall; external Dll; function CamGetCaptureMode(hCapture: HCAMREC; var pMode: camCaptureMode): BOOL; stdcall; external Dll; function CamSetCaptureAppAudioFormat(hCapture: HCAMREC; lpWaveFormat: Pointer): BOOL; stdcall; external Dll; function CamGetCaptureAppAudioFormat(hCapture: HCAMREC; lpWaveFormat: Pointer): BOOL; stdcall; external Dll; function CamSetMuteAudio(hCapture: HCAMREC; bEnable: BOOL): BOOL; stdcall; external Dll; function CamGetMuteAudio(hCapture: HCAMREC; var pbEnable: BOOL): BOOL; stdcall; external Dll; // Capture Callbacks function CamSetStateChangeCallback(hCapture: HCAMREC; lpfnCamStateChangeProc: CAMSTATECHANGEPROC; dwData: DWORD): BOOL; stdcall; external Dll; function CamGetStateChangeCallback(hCapture: HCAMREC; var lpfnCamStateChangeProc: CAMSTATECHANGEPROC; var pdwData: DWORD): BOOL; stdcall; external Dll; function CamSetErrorCallback(hCapture: HCAMREC; lpfnCamErrorProc: CAMERRORPROC; dwData: DWORD): BOOL; stdcall; external Dll; function CamGetErrorCallback(hCapture: HCAMREC; var lpfnCamErrorProc: CAMERRORPROC; var pdwData: DWORD): BOOL; stdcall; external Dll; function CamSetVideoCallback(hCapture: HCAMREC; lpfnCamVideoProc: CAMVIDEOPROC; bCursorInfo: BOOL; dwData: DWORD): BOOL; stdcall; external Dll; function CamGetVideoCallback(hCapture: HCAMREC; var lpfnCamVideoProc: CAMVIDEOPROC; var pbCursorInfo: BOOL; var pdwData: DWORD): BOOL; stdcall; external Dll; // Capture runtime statistics function CamGetCaptureState(hCapture: HCAMREC): camState; stdcall; external Dll; function CamGetFrameCount(hCapture: HCAMREC): DWORD; stdcall; external Dll; function CamGetEffectiveFrameRate(hCapture: HCAMREC): Single; stdcall; external Dll; function CamGetDroppedFrameCount(hCapture: HCAMREC): DWORD; stdcall; external Dll; function CamGetMediaLength(hCapture: HCAMREC): DWORD; stdcall; external Dll; // File Properties function CamSetFileSaveDialog(hCapture: HCAMREC; bEnable: BOOL): BOOL; stdcall; external Dll; function CamGetFileSaveDialog(hCapture: HCAMREC; var pbEnable: BOOL): BOOL; stdcall; external Dll; function CamSetFileSaveDialogOwnerWindow(hCapture: HCAMREC; hwndOwner: HWND): BOOL; stdcall; external Dll; function CamGetFileSaveDialogOwnerWindow(hCapture: HCAMREC; var phwndOwner: HWND): BOOL; stdcall; external Dll; function CamSetFileNameA(hCapture: HCAMREC; const szFileName: PChar): BOOL; stdcall; external Dll; function CamGetFileNameA(hCapture: HCAMREC; szFileName: PChar): BOOL; stdcall; external Dll; function CamSetFileNameW(hCapture: HCAMREC; const szFileName: PWChar): BOOL; stdcall; external Dll; function CamGetFileNameW(hCapture: HCAMREC; szFileName: PWChar): BOOL; stdcall; external Dll; function CamSetTempFolderA(hCapture: HCAMREC; const szTempFolder: PChar; const szPrefix: PChar): BOOL; stdcall; external Dll; function CamGetTempFolderA(hCapture: HCAMREC; szTempFolder: PChar; szPrefix: PChar): BOOL; stdcall; external Dll; function CamSetTempFolderW(hCapture: HCAMREC; const szTempFolder: PWChar; const szPrefix: PWChar): BOOL; stdcall; external Dll; function CamGetTempFolderW(hCapture: HCAMREC; szTempFolder: PWChar; szPrefix: PWChar): BOOL; stdcall; external Dll; // AVI Properties function CamSetAviDataRate(hCapture: HCAMREC; dwDataRate: DWORD): BOOL; stdcall; external Dll; function CamGetAviDataRate(hCapture: HCAMREC; var pdwDataRate: DWORD): BOOL; stdcall; external Dll; function CamSetAviQuality(hCapture: HCAMREC; dwQuality: DWORD): BOOL; stdcall; external Dll; function CamGetAviQuality(hCapture: HCAMREC; var pdwQuality: DWORD): BOOL; stdcall; external Dll; function CamSetAviKeyframeRate(hCapture: HCAMREC; dwKeyFrameRate: DWORD): BOOL; stdcall; external Dll; function CamGetAviKeyframeRate(hCapture: HCAMREC; var pdwKeyFrameRate: DWORD): BOOL; stdcall; external Dll; function CamSetAviVideoCodec(hCapture: HCAMREC; fccHandler: DWORD): BOOL; stdcall; external Dll; function CamGetAviVideoCodec(hCapture: HCAMREC; var pfccHandler: DWORD): BOOL; stdcall; external Dll; function CamSetAviAudioFormat(hCapture: HCAMREC; lpWaveFormat: Pointer): BOOL; stdcall; external Dll; function CamGetAviAudioFormat(hCapture: HCAMREC; lpWaveFormat: Pointer; var pdwSize: DWORD): BOOL; stdcall; external Dll; function CamSetAviInterleave(hCapture: HCAMREC; Mode: camAviInterleaveMode; dwInterleaveRate: DWORD): BOOL; stdcall; external Dll; function CamGetAviInterleave(hCapture: HCAMREC; var pMode: camAviInterleaveMode; var pdwInterleaveRate: DWORD): BOOL; stdcall; external Dll; function CamSetAviCustomPlaybackFrameRate(hCapture: HCAMREC; bEnable: BOOL): BOOL; stdcall; external Dll; function CamGetAviCustomPlaybackFrameRate(hCapture: HCAMREC; var pbEnable: BOOL): BOOL; stdcall; external Dll; function CamSetAviPlaybackFrameRate(hCapture: HCAMREC; dwRate: DWORD; dwScale: DWORD; Base: camFrameRateBase): BOOL; stdcall; external Dll; function CamGetAviPlaybackFrameRate(hCapture: HCAMREC; var pdwRate: DWORD; var pdwScale: DWORD; var pBase: camFrameRateBase): BOOL; stdcall; external Dll; // Miscellaneous function CamGetLastError(hCapture: HCAMREC): camError; stdcall; external Dll; function CamResetProperties(hCapture: HCAMREC; PropertyType: camPropertyType): BOOL; stdcall; external Dll; function CamAviVideoPropertiesDialog(hCapture: HCAMREC; hwndOwner: HWND): BOOL; stdcall; external Dll; function CamAviAudioPropertiesDialog(hCapture: HCAMREC; hwndOwner: HWND): BOOL; stdcall; external Dll; function CamGetAudioDevices(hCapture: HCAMREC): DWORD; stdcall; external Dll; type camControl = ( cConPause = 0, cConResum = 1, cConStop = 2 ); TRECObj = class class procedure CreateCapture(Wnd: THandle); class function CaptureStart(AviFile: string; pRc: PRect = nil; RecWindow: THandle=0): Boolean; class function CaptureControl(AControl: camControl): Boolean; class procedure DestroyCapture(); end; var g_hCapture: HCAMREC; g_IsIni: Boolean = False; implementation { TRECObj } class procedure TRECObj.CreateCapture(Wnd: THandle); begin if g_IsIni then Exit; g_IsIni := True; g_hCapture := CamCreateCaptureA(PChar('097A3AE70C70B2063F')); CamSetFileSaveDialogOwnerWindow(g_hCapture, Wnd); end; class procedure TRECObj.DestroyCapture; begin CamDestroyCapture(g_hCapture); end; class function TRECObj.CaptureControl(AControl: camControl): Boolean; begin case AControl of cConPause: Result := CamPauseCapture(g_hCapture); cConResum: Result := CamResumeCapture(g_hCapture); cConStop: Result := CamStopCapture(g_hCapture); end; end; {:函数说明} { AviFile: 录制的文件名 文件名为空时, 会弹出文件名对话框 pRc: 录制的范围 RecWindow: 录制的窗口 关于范围的优先顺序: 窗口句柄不为0时, 以窗口范围为准 窗口句柄为0时, 以范围为准, 若范围也为0, 那么默认录制整个桌面. TRECObj.CaptureStart(''); //录制桌面, 弹出保存文件对话框 TRECObj.CaptureStart('d:\168.avi'); //录制桌面 文件为 d:\168.avi rc := Rect(0,0,640, 480); TRECObj.CaptureStart('d:\168.avi', @rc); //录制范围(0,0,640,480)的区域 TRECObj.CaptureStart('d:\168.avi', nil, Handle); 录制Handle所在的区域 } class function TRECObj.CaptureStart(AviFile: string; pRc: PRect; RecWindow: THandle): Boolean; begin CamSetCaptureMode(g_hCapture, ccmNormal); CamSetHideCaptureRectangle(g_hCapture, True); CamSetOutput(g_hCapture, coutFile); CamSetRecordCursor(g_hCapture, True); if RecWindow <> 0 then CamSetInput(g_hCapture, cinWindow, RecWindow, pRc) else if pRc <> nil then CamSetInput(g_hCapture, cinRegion, 0, pRc) else CamSetInput(g_hCapture, cinScreen, 0, pRc); CamSetAudioSource(g_hCapture, casWaveIn); if AviFile <> '' then begin CamSetFileSaveDialog(g_hCapture, False); CamSetFileNameA(g_hCapture, PChar(AviFile)); end else CamSetFileSaveDialog(g_hCapture, True); CamStartCapture(g_hCapture); end; end.
使用方法, 很简单
View Code
procedure TForm1.FormCreate(Sender: TObject); begin TRECObj.CreateCapture(Handle); end; procedure TForm1.FormDestroy(Sender: TObject); begin TRECObj.DestroyCapture(); end; procedure TForm1.btn1Click(Sender: TObject); var rc: TRect; begin // TRECObj.CaptureStart(''); TRECObj.CaptureStart('d:\168.avi'); // rc := Rect(0,0,640, 480); // TRECObj.CaptureStart('d:\168.avi', @rc); // TRECObj.CaptureStart('d:\168.avi', nil, Handle); end; procedure TForm1.btn2Click(Sender: TObject); begin TRECObj.CaptureControl(cConPause); end; procedure TForm1.btn3Click(Sender: TObject); begin TRECObj.CaptureControl(cConResum); end; procedure TForm1.btn4Click(Sender: TObject); begin TRECObj.CaptureControl(cConStop); end;