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;
    Memo1: TMemo;
    Memo2: TMemo;
    Image1: TImage;
    Label2: TLabel;
    Label3: TLabel;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Memo1Change(Sender: TObject);
    procedure Memo2Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  //fpengine.SetMsgMainHandle(self.Handle);
  if(fpengine.OpenDevice(0,0,0)=1)then
    fpengine.LinkDevice;
  //fpengine.SetDispOption(1,0.75,RGB(255,255,255),RGB(255,0,0));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  fpengine.CloseDevice;
  fpengine.OpenDevice(0,0,0);
  fpengine.LinkDevice;
  SetStatusLed(0,1);
  fpengine.EnrolFpChar;
  Timer1.Enabled:=True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  fpengine.CloseDevice;
  fpengine.OpenDevice(0,0,0);
  fpengine.LinkDevice;
  SetStatusLed(0,0);
  fpengine.GenFpChar;
  Timer1.Enabled:=True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  fpm,ret:Integer;
  tpdata:array[0..4095]of char;
  iscope:Integer;
  tp1,tp2:String;
  bmp:TBitmap;

  tpchar:array[0..256]of BYTE;
  tpsize:Integer;
  fs:TFileStream;
begin
  fpm:=fpengine.GetWorkMsg;
  ret:=fpengine.GetRetMsg;
  case fpm of
  FPM_DEVICE: begin Label1.Caption:='设备未打开'; end;
  FPM_PLACE:  begin Label1.Caption:='请按手指'; end;
  FPM_LIFT:   begin Label1.Caption:='请抬起手指'; end;
  //FPM_CAPTURE:		//采集图像
  FPM_ENROLL:   //登记用户
    begin
      if ret=RET_OK then
      begin
        Label1.Caption:='登记手指完成';
        ZeroMemory(@tpdata,4096);
        fpengine.GetFpStrByEnl(tpdata[0]);
        memo1.Lines.Clear;
        memo1.Lines.Add(tpdata);
      end else
      begin
        Label1.Caption:='登记手指失败';
        memo1.Lines.Clear;
      end;
      Timer1.Enabled:=False;
    end;
  FPM_GENCHAR:     //采集特征点
    begin
      if ret=RET_OK then
      begin
        Label1.Caption:='采集特征点完成';
        ZeroMemory(@tpdata,4096);
        fpengine.GetFpStrByGen(tpdata[0]);
        fpengine.GetFpCharByGen(tpchar[0],tpsize);
        fs:=TFileStream.Create('.\char.dat',fmCreate);
        fs.Write(tpchar,tpsize);
        fs.Free;
        memo2.Lines.Clear;
        memo2.Lines.Add(tpdata);
        if memo1.GetTextLen()>0 then
        begin
          tp1:=memo1.Lines.Text;
          tp2:=memo2.Lines.Text;
          iscope:=fpengine.MatchTemplateEx(tp2[1],tp1[1]);
          Label1.Caption:='比对分数:'+IntToStr(iscope);
        end;
      end else
      begin
        Label1.Caption:='采集特征点失败';
        memo2.Lines.Clear;
      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;

procedure TForm1.Memo1Change(Sender: TObject);
begin
  Label2.Caption:=IntToStr(memo1.GetTextLen);
end;

procedure TForm1.Memo2Change(Sender: TObject);
begin
    Label3.Caption:=IntToStr(memo2.GetTextLen);
end;

end.
