這是我參考所打出來的程式~但是跑程式時卻會leg~不知是哪裡沒設到ㄋ??
#include
#pragma hdrstop
#include "Unit1.h"
#include
#include
HWND hCapWnd;
BITMAPINFO bmi;
int ConnectDeviceIndex;
int ImageWidth,ImageHeight;
#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
} void __fastcall TForm1::Btn_PREVIEWClick(TObject *Sender)
{
hCapWnd = capCreateCaptureWindow("My Capture Window",
WS_CHILD | WS_VISIBLE,
0, 0,
ImageWidth,
ImageHeight,
Form1->Panel1->Handle,
0 ); for(ConnectDeviceIndex=0; ConnectDeviceIndex<10; ConnectDeviceIndex )
if (capDriverConnect(hCapWnd, ConnectDeviceIndex))
break; if(ConnectDeviceIndex>=10) ShowMessage("攝影機連接失敗..");
else
{
capGetVideoFormat(hCapWnd, &bmi, sizeof(BITMAPINFO));
bmi.bmiHeader.biWidth=320;
bmi.bmiHeader.biHeight=240;
if (capSetVideoFormat(hCapWnd, &bmi, sizeof(BITMAPINFO)))
{
capDriverDisconnect(hCapWnd);
capDriverConnect(hCapWnd, ConnectDeviceIndex);
} capOverlay(hCapWnd, true);
capPreviewScale(hCapWnd,true);
capPreviewRate(hCapWnd, 1000/30);
capGetVideoFormat(hCapWnd, &bmi, sizeof(BITMAPINFO));
SetWindowPos(hCapWnd, 0, 0, 0, bmi.bmiHeader.biWidth,bmi.bmiHeader.biHeight, 0);
// capPreview(hCapWnd,true);
} Timer1->Enabled=true;
Btn_STOP->Enabled=true;
Btn_PREVIEW->Enabled=false;
//CheckBox1->Enabled=true;
} void __fastcall TForm1::Btn_STOPClick(TObject *Sender)
{
Timer1->Enabled = false;
capPreview(hCapWnd, false);
capDriverDisconnect(hCapWnd);
Btn_STOP->Enabled=false;
Btn_PREVIEW->Enabled=true;
//CheckBox1->Enabled=false;
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Timer1->Enabled=false;
capGrabFrameNoStop(hCapWnd);
capEditCopy(hCapWnd);
//if(Clipboard()->HasFormat(CF_DIB))
//Image3->Picture->Bitmap->Assign(Clipboard());
//Bitmap1->Assign(Image3->Picture); //if (CheckBox1->Checked==true)
//Button2Click(Sender); Timer1->Enabled=true;
}≠