//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "vfw.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char szDeviceName[80];
char szDeviceVersion[80];
for (int wIndex=0;wIndex<10;wIndex++)
{
if (capGetDriverDescription(wIndex,szDeviceName,sizeof(szDeviceName),szDeviceVersion,sizeof(szDeviceVersion)))
{
Camera->Items->Add(szDeviceName);
}
}
if(Camera->Items->Count>0)
Camera->ItemIndex=0;
else
{
ShowMessage("There is no camera!");
Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
HWND hWndC=capCreateCaptureWindow((LPSTR)"My Capture Window",WS_CHILD | WS_VISIBLE,0,0,160,120,(HWND)Panel2->Handle,Camera->ItemIndex+1);
//连接设备:
capDriverConnect(hWndC,0);
capPreviewRate(hWndC,50); // rate, in milliseconds
capPreview(hWndC,TRUE); // starts preview
//获取视频驱动相关性能
CAPDRIVERCAPS CapDrvCaps;
capDriverGetCaps(hWndC,&CapDrvCaps,sizeof(CAPDRIVERCAPS));
//获取捕获窗口状态
CAPSTATUS CapStatus ;
capGetStatus(hWndC,&CapStatus,sizeof(CAPSTATUS));
SetWindowPos((HWND)Panel2->Handle,NULL,0,0,CapStatus.uiImageWidth,CapStatus.uiImageHeight,SWP_NOZORDER | SWP_NOMOVE);
SetWindowPos(hWndC,NULL,0,0,CapStatus.uiImageWidth,CapStatus.uiImageHeight,SWP_NOZORDER | SWP_NOMOVE);
//文章出处:DIY部落(http://www.diybl.com/course/3_program/c++/cppsl/20071128/87976.html#)
}
//---------------------------------------------------------------------------
评论0