#include <vcl.h>
#include <Vfw.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
//---------------------------------------------------------------------------
HWND hWndCap;
BITMAPINFO bi;
LRESULT CALLBACK capVideoStreamCallback(HWND hWnd, LPVIDEOHDR lpVHdr)
{
HBITMAP hb;
HDC hDC;
hDC = GetDC(Form1->Panel1->Handle);
hb = CreateCompatibleBitmap(hDC, SCREEN_WIDTH, SCREEN_HEIGHT);
SetDIBits(hDC, hb, 0, SCREEN_HEIGHT, lpVHdr->lpData, &bi, DIB_RGB_COLORS);
BITMAP bm;
HDC hMemDC;
POINT pt;
if(hb)
{
hMemDC = CreateCompatibleDC(hDC);
SelectObject(hMemDC, hb);
GetObject(hb, sizeof(BITMAP), (LPSTR)&bm);
BitBlt(hDC, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, hMemDC, 0, 0, SRCCOPY);
DeleteDC(hMemDC);
}
Rectangle(hDC, 100, 100, 120, 120);
ReleaseDC(NULL, hDC);
DeleteObject(hb);
return (LRESULT)TRUE;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
hWndCap = capCreateCaptureWindow("default_cam", WS_CHILD | WS_VISIBLE,
0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Form1->Handle, 0);
capSetCallbackOnFrame(hWndCap, capVideoStreamCallback);
bool bReady = capDriverConnect(hWndCap, 0);
if(bReady)
{
bool bOK;
DWORD dwSize = capGetVideoFormatSize(hWndCap);
capGetVideoFormat(hWndCap, &bi, dwSize);
bOK = capPreviewRate(hWndCap, 67); //67ms = 15fps
bOK = capPreview(hWndCap, true);
}
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
capPreview(hWndCap, false);
DestroyWindow(hWndCap);
}