//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "captura_cam.h"
#include "Vfw.h"
#include "main.h"
#include "histograma.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm12 *Form12;

CAPDRIVERCAPS CapDrvCaps;
bool encendida=false;

//---------------------------------------------------------------------------
__fastcall TForm12::TForm12(TComponent* Owner)
	: TForm(Owner)
{


}
//---------------------------------------------------------------------------
void __fastcall TForm12::Button1Click(TObject *Sender)
{
   boolean fOK;

   if (encendida==false) {
      // capDlgVideoSource(id);
  visor=capCreateCaptureWindowA("ventana", WS_VISIBLE|WS_CHILD,0,0,320,200,Panel1->Handle,0);

  if (visor!=0) {

   fOK = SendMessage (visor, WM_CAP_DRIVER_CONNECT, 0, 0L);

	 capPreviewRate(visor, 30);
	 capPreview(visor, TRUE);
//para ver si el render va con overlay
capDriverGetCaps(visor, &CapDrvCaps, sizeof (CAPDRIVERCAPS));

if (CapDrvCaps.fHasOverlay)
	capOverlay(visor, TRUE);

	Button5->Enabled=true;
	Button2->Enabled=true;

  } else {
	  ShowMessage("Hay algun problema con tu camara");
  }
  encendida=true;
  Button1->Caption="Apagar";

   } else {
		 fOK = SendMessage (visor, WM_CAP_DRIVER_DISCONNECT, 0, 0L);
		 encendida=false;
		 Button1->Caption="Encender";
   }

}
//---------------------------------------------------------------------------

void __fastcall TForm12::Button5Click(TObject *Sender)
{
 capDlgVideoSource(visor);
}
//---------------------------------------------------------------------------


void __fastcall TForm12::Button2Click(TObject *Sender)
{
HDC dc;

  dc=GetDC(Panel1->Handle);
  BitBlt(Image2->Canvas->Handle,0,0,320,240,dc,0,0,SRCCOPY);
  ReleaseDC(0,dc);
  Button3->Enabled=true;

}
//---------------------------------------------------------------------------

void __fastcall TForm12::Button3Click(TObject *Sender)
{
  SendMessage(visor, WM_CAP_DRIVER_DISCONNECT, 0, 0);
  Form1->CreaNuevo(Image2->Picture->Bitmap->Width,Image2->Picture->Bitmap->Height,24);
  Form1->pasaImagen(Image2->Picture);
  Form12->Hide();
}
//---------------------------------------------------------------------------

void __fastcall TForm12::Button4Click(TObject *Sender)
{
  Form12->Hide();
}
//---------------------------------------------------------------------------

