完整的程序代码如下
unit Unit;
interface
uses
Windows Messages SysUtils Variants Classes Graphics Controls Forms
Dialogs StdCtrls ExtCtrls;
type
TForm = class(TForm)
Panel: TPanel;
Button: TButton;
Button: TButton;
Button: TButton;
Button: TButton;
Button: TButton;
procedure ButtonClick(Sender: TObject);
procedure ButtonClick(Sender: TObject);
procedure ButtonClick(Sender: TObject);
procedure ButtonClick(Sender: TObject);
procedure ButtonClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
hWndC : THandle;
public
{ Public declarations }
end;
var
Form: TForm;
const WM_CAP_START = WM_USER;
const WM_CAP_STOP = WM_CAP_START + ;
const WM_CAP_DRIVER_CONNECT = WM_CAP_START + ;
const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + ;
const WM_CAP_SAVEDIB = WM_CAP_START + ;
const WM_CAP_GRAB_FRAME = WM_CAP_START + ;
const WM_CAP_SEQUENCE = WM_CAP_START + ;
const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + ;
const WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+
const WM_CAP_SET_OVERLAY =WM_CAP_START+
const WM_CAP_SET_PREVIEW =WM_CAP_START+
const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +;
const WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +;
const WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +;
const WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +;
const WM_CAP_SET_SCALE=WM_CAP_START+
const WM_CAP_SET_PREVIEWRATE=WM_CAP_START+
function capCreateCaptureWindowA(lpszWindowName : PCHAR;
dwStyle : longint;x : integer;y : integer;nWidth : integer;
nHeight : integer;ParentWin : HWND;nId : integer): HWND;
STDCALL EXTERNAL AVICAPDLL;
implementation
{$R *dfm}
procedure TFormButtonClick(Sender: TObject);
begin
hWndC := capCreateCaptureWindowA(My Own Capture WindowWS_CHILD or WS_VISIBLE PanelLeftPanelTopPanelWidthPanelHeightFormHandle);
hWndC := capCreateCaptureWindowA(My Own Capture WindowWS_CHILD or WS_VISIBLE PanelLeftPanelTopPanelWidthPanelHeightFormHandle);
if hWndC <> then
begin
SendMessage(hWndC WM_CAP_SET_CALLBACK_VIDEOSTREAM );
SendMessage(hWndC WM_CAP_SET_CALLBACK_ERROR );
SendMessage(hWndC WM_CAP_SET_CALLBACK_STATUSA );
SendMessage(hWndC WM_CAP_DRIVER_CONNECT );
SendMessage(hWndC WM_CAP_SET_SCALE );
SendMessage(hWndC WM_CAP_SET_PREVIEWRATE );
SendMessage(hWndC WM_CAP_SET_OVERLAY );
SendMessage(hWndC WM_CAP_SET_PREVIEW );
end;
end;
procedure TFormButtonClick(Sender: TObject);
begin
if hWndC <> then begin
SendMessage(hWndC WM_CAP_DRIVER_DISCONNECT );
hWndC := ;
end;
end;
procedure TFormButtonClick(Sender: TObject);
begin
if hWndC <> then begin
SendMessage(hWndCWM_CAP_SAVEDIBlongint(pchar(c:\testbmp)));
end;
end;
procedure TFormButtonClick(Sender: TObject);
begin
if hWndC <> then
begin
SendMessage(hWndCWM_CAP_FILE_SET_CAPTURE_FILEA Longint(pchar(c:\testavi)));
SendMessage(hWndC WM_CAP_SEQUENCE );
end;
end;
procedure TFormButtonClick(Sender: TObject);
begin
if hWndC <> then begin
SendMessage(hWndC WM_CAP_STOP );
end;
end;
procedure TFormFormClose(Sender: TObject; var Action: TCloseAction);
begin
if hWndC <> then begin
SendMessage(hWndC WM_CAP_DRIVER_DISCONNECT );
end;
end;
end
如果电脑没有摄像头但又想看看程序的效果可以么?
当然可以找个虚拟摄像头不就搞定大家可以试试SoftCam这个软件它是一个名副其实的软件摄像机能模拟成为真实的摄像机提醒一下各位大家可不要用这个东东用在QQMSN等聊天软件上欺骗MM或GG啊
关于摄像头编程大家也可以看看这组VCL组件DSPackDSPack是一套使用微软Direct Show和DirectX技术的类和组件设计工作于DirectX 支持系统WinX ME 和Windows XP
好了就介绍这些了至于视屏聊天怎么实现就看你的了无非是把数据压缩传输给对方显示出来不过话又说回来看似简单实现起来还有些难度的