unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,fpengine, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    enltp:array[0..511]of BYTE;
    enlsize:Integer;
    mattp:array[0..255]of BYTE;
    matsize:Integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  fpengine.CloseDevice;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  //fpengine.SetMsgMainHandle(self.Handle);
  if(fpengine.OpenDevice(0,0,0)=1)then
  begin
    if fpengine.LinkDevice(0)=1 then
    begin
      Label1.Caption:='Link Device OK';
    end else
    begin
      Label1.Caption:='Link Device Fail';
    end;
  end else
  begin
    Label1.Caption:='Open Device Fail';
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  fpengine.EnrollTemplate;
  Timer1.Enabled:=True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  fpengine.CaptureTemplate;
  Timer1.Enabled:=True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  fpm,ret:Integer;
  sc:Integer;
  bmp:TBitmap;
  fs:TFileStream;
begin
  fpm:=fpengine.GetWorkMsg;
  ret:=fpengine.GetRetMsg;
  case fpm of
  FPM_DEVICE: begin Label1.Caption:='Please Open Device'; end;
  FPM_PLACE:  begin Label1.Caption:='Place Finger ...'; end;
  FPM_LIFT:   begin Label1.Caption:='Lift Finger ...'; end;
  FPM_ENROLL:
    begin
      if ret=RET_OK then
      begin
        Label1.Caption:='Enrol OK';
        fpengine.GetTemplateByEnl(enltp[0],enlsize);
      end else
      begin
        Label1.Caption:='Enrol Fail';
      end;
      Timer1.Enabled:=False;
    end;
  FPM_GENCHAR:
    begin
      if ret=RET_OK then
      begin
        Label1.Caption:='Captrue OK';
        fpengine.GetTemplateByCap(mattp[0],matsize);
        if enlsize>0 then
        begin
          sc:=fpengine.MatchTemplateOne(mattp[0],enltp[0],enlsize);
          if sc>=80 then
          begin
            Label1.Caption:='Match OK';
          end else
          begin
            Label1.Caption:='Match Fail';
          end;
        end;
      end else
      begin
        Label1.Caption:='Captrue Fail';
      end;
      Timer1.Enabled:=False;
    end;
  FPM_NEWIMAGE:
    begin
      fpengine.DrawImage(Canvas.Handle,8,48);
      {
      bmp:=TBitmap.Create;
      bmp.PixelFormat:=pf8bit;
      bmp.Width:=256;
      bmp.Height:=288;
      fpengine.DrawImage(bmp.Canvas.Handle,0,0);
      //fpengine.DrawImageEx(bmp.Canvas.Handle,0,0,0,RGB(0,0,255));
      Image1.Picture.Bitmap.Assign(bmp);
      bmp.Free;
      }
    end;
  end;
end;

end.
