📄 authentication.cpp
字号:
// Authentication.cpp : implementation file
//
#include "stdafx.h"
#include "FingerDemo.h"
#include "Authentication.h"
#include "fingerdll.h"
#include "scandialog.h"
#include "zhongzhgetbmp.h"
#include "Setreader.h"
#include "MbtoIC.h"
#include "Fcom.h"
#include "captipdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAuthentication
extern CFingerDemoApp theApp;
IMPLEMENT_DYNCREATE(CAuthentication, CFormView)
CAuthentication::CAuthentication()
: CFormView(CAuthentication::IDD)
{
//{{AFX_DATA_INIT(CAuthentication)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
sbmp1=new Scan_Bmp();
sbmp2=new Scan_Bmp();
sbmp1->ReadFile(theApp.m_ProgramePath+"\\Samplea.bmp");
sbmp1->Copy(*sbmp2);
m_Minutia1=(unsigned char*)GlobalAlloc(GMEM_FIXED,MAXNUM*DIM+4);
m_Minutia2=(unsigned char*)GlobalAlloc(GMEM_FIXED,MAXNUM*DIM+4);
memset(m_Minutia1,0,MAXNUM*DIM+4);
memset(m_Minutia2,0,MAXNUM*DIM+4);
quli1=type1=quli2=type2=0;
cenx1=ceny1=cenx2=ceny2=0;
theApp.m_pAuthenView =this;
}
CAuthentication::~CAuthentication()
{
GlobalFree(m_Minutia1);
GlobalFree(m_Minutia2);
delete sbmp1;
delete sbmp2;
theApp.m_bFingerAuthen=false;
}
void CAuthentication::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAuthentication)
DDX_Control(pDX, IDC_FINGER_BMP2, m_Image2);
DDX_Control(pDX, IDC_FINGER_BMP1, m_Image1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAuthentication, CFormView)
//{{AFX_MSG_MAP(CAuthentication)
ON_BN_CLICKED(IDC_INPORT_BMPFILE1, OnInportBmpfile1)
ON_BN_CLICKED(IDC_INPORT_BMPFILE2, OnInportBmpfile2)
ON_BN_CLICKED(IDC_INPORT_CAPTURE2, OnInportCapture2)
ON_BN_CLICKED(IDC_AUTHENTICATE, OnAuthenticate)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_SET_READER, OnSetReader)
ON_BN_CLICKED(IDC_WRITE_IC, OnWriteIc)
ON_BN_CLICKED(IDC_IC_AUTHENTICATE, OnIcAuthenticate)
ON_BN_CLICKED(IDC_IC_INQUIRE, OnIcInquire)
ON_BN_CLICKED(IDC_IC_MATCH, OnIcMatch)
ON_BN_CLICKED(IDC_INPORT_CAPTURE3, OnInportCapture1)
ON_BN_CLICKED(IDC_SET_PORT, OnSetPort)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAuthentication diagnostics
#ifdef _DEBUG
void CAuthentication::AssertValid() const
{
CFormView::AssertValid();
}
void CAuthentication::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CAuthentication message handlers
void CAuthentication::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
if(sbmp1)
sbmp1->DrawDib(m_Image1.GetDC(),1,0,0);
if(sbmp2)
sbmp2->DrawDib(m_Image2.GetDC(),1,0,0);
}
void CAuthentication::OnInportBmpfile1()
{
// TODO: Add your control notification handler code here
CFileDialog fg(TRUE, // TRUE for FileOpen, FALSE for FileSaveAs
"*.bmp",
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"位图文件(*.bmp)|*.bmp",
this);
if(fg.DoModal() == IDOK)
{
CString fn;
fn=fg.GetFileName();
Scan_Bmp *tmp=new Scan_Bmp();
tmp->ReadFile(fn);
sbmp1->ExtendSmallBmp(tmp);
CPaintDC dc(this); // device context for painting
sbmp1->DrawDib(m_Image1.GetDC(),1,0,0);
}
if(!GetMinutia(sbmp1->m_Bmp_pBmpValue,NULL,sbmp1->m_Height,sbmp1->m_Width ,m_Minutia1,quli1,type1,cenx1,ceny1))
{
MessageBox("第一枚指纹图像不合格","注意",MB_OK);
return;
}
RECT rc;
GetDlgItem(IDC_FINGER_BMP1)->GetWindowRect(&rc);
InvalidateRect(&rc);
}
void CAuthentication::OnInportCapture1()
{
// TODO: Add your control notification handler code here
if(theApp.cap_type==1)//////////光电指纹采集仪采集图像/////////////////////
{
CScanDialog gfr(sbmp1);
if(gfr.DoModal()==IDOK)
{
if(!GetMinutia(sbmp1->m_Bmp_pBmpValue,NULL,sbmp1->m_Height,sbmp1->m_Width ,m_Minutia1,quli1,type1,cenx1,ceny1))
{
MessageBox("第一枚指纹图像不合格","注意",MB_OK);
return;
}
RECT rc;
GetDlgItem(IDC_FINGER_BMP1)->GetWindowRect(&rc);
InvalidateRect(&rc);
}
}
else if(theApp.cap_type==2)/////////////电容传感器采集指纹图像////////////
{
CZhongzhGetBmp zz;
zz.GetBmp(sbmp1);
if(!GetMinutia(sbmp1->m_Bmp_pBmpValue,NULL,sbmp1->m_Height,sbmp1->m_Width ,m_Minutia1,quli1,type1,cenx1,ceny1))
{
MessageBox("第一枚指纹图像不合格","注意",MB_OK);
return;
}
RECT rc;
GetDlgItem(IDC_FINGER_BMP1)->GetWindowRect(&rc);
InvalidateRect(&rc);
}
}
void CAuthentication::OnInportBmpfile2()
{
// TODO: Add your control notification handler code here
CFileDialog fg(TRUE, // TRUE for FileOpen, FALSE for FileSaveAs
"*.bmp",
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"位图文件(*.bmp)|*.bmp",
this);
if(fg.DoModal() == IDOK)
{
CString fn;
fn=fg.GetFileName();
Scan_Bmp *tmp=new Scan_Bmp();
tmp->ReadFile(fn);
sbmp2->ExtendSmallBmp(tmp);
CPaintDC dc(this); // device context for painting
sbmp2->DrawDib(m_Image2.GetDC(),1,0,0);
}
if(!GetMinutia(sbmp2->m_Bmp_pBmpValue,NULL,sbmp2->m_Height,sbmp2->m_Width ,m_Minutia2,quli2,type2,cenx2,ceny2))
{
MessageBox("第二枚指纹图像不合格","注意",MB_OK);
return;
}
RECT rc;
GetDlgItem(IDC_FINGER_BMP2)->GetWindowRect(&rc);
InvalidateRect(&rc);
}
void CAuthentication::OnInportCapture2()
{
// TODO: Add your control notification handler code here
if(theApp.cap_type==1)//////////光电指纹采集仪采集图像/////////////////////
{
CScanDialog gfr(sbmp2);
if(gfr.DoModal()==IDOK)
{
if(!GetMinutia(sbmp2->m_Bmp_pBmpValue,NULL,sbmp2->m_Height,sbmp2->m_Width ,m_Minutia2,quli2,type2,cenx2,ceny2))
{
MessageBox("第二枚指纹图像不合格","注意",MB_OK);
return;
}
RECT rc;
GetDlgItem(IDC_FINGER_BMP2)->GetWindowRect(&rc);
InvalidateRect(&rc);
}
}
else if(theApp.cap_type==2)/////////////电容传感器采集指纹图像////////////
{
CZhongzhGetBmp zz;
zz.GetBmp(sbmp2);
if(!GetMinutia(sbmp2->m_Bmp_pBmpValue,NULL,sbmp2->m_Height,sbmp2->m_Width ,m_Minutia2,quli2,type2,cenx2,ceny2))
{
MessageBox("第二枚指纹图像不合格","注意",MB_OK);
return;
}
RECT rc;
GetDlgItem(IDC_FINGER_BMP2)->GetWindowRect(&rc);
InvalidateRect(&rc);
}
}
void CAuthentication::OnAuthenticate()
{
// TODO: Add your control notification handler code here
/* if(type1!=type2)
{
MessageBox("两枚指纹纹型不符,身份认证失败!","结果",MB_OK);
return;
}
*/
int res;
res=FingerMatch(m_Minutia1,m_Minutia2,cenx1,ceny1,cenx2,ceny2);
if(res>=theApp.m_nMatchDoor)
{
CDialog *pdlg=new CDialog();
pdlg->Create(IDD_MATCH_OK_DLG);
pdlg->ShowWindow(SW_SHOWNORMAL );
// MessageBox("两枚指纹相符合,身份认证成功!!!","结果",MB_OK);
}
else
{
CDialog *pdlg=new CDialog();
pdlg->Create(IDD_MATCH_NOT_DLG);
pdlg->ShowWindow(SW_SHOWNORMAL );
// MessageBox("两枚指纹不符,身份认证失败!","结果",MB_OK);
}
}
HBRUSH CAuthentication::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor==CTLCOLOR_EDIT||nCtlColor==CTLCOLOR_LISTBOX)
return hbr;
else
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(theApp.m_textcolor);
return ((HBRUSH)::GetStockObject(HOLLOW_BRUSH));
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
BOOL CAuthentication::OnEraseBkgnd(CDC* pDC)
{
theApp.backbmp.ReadFile(theApp.m_backfilename);//"c:\\z1.bmp"
CRect rect;
GetClientRect(&rect);
for (int nX = 0; nX < rect.Width(); nX +=theApp.backbmp. m_Width)
for (int nY = 0; nY < rect.Height(); nY +=theApp.backbmp. m_Height)
theApp.backbmp.DrawDib(pDC,1,nX,nY);
return TRUE;
}
void CAuthentication::OnSetReader() //by limeihong 2002-8-14
{
// TODO: Add your control notification handler code here
CSetreader setreader;
setreader.DoModal();
}
//write the finger template to IC card
void CAuthentication::OnWriteIc() //by limeihong 2002-8-14
{
// TODO: Add your control notification handler code here
CMbtoIC m_writeic;
unsigned char mbx,mby;
mbx = (unsigned char)cenx1;
mby = (unsigned char)ceny1;
m_Minutia1[200] = mbx;
m_Minutia1[201] = mby;
if(m_writeic.WriteBinarytoIC(202,m_Minutia1))
{
AfxMessageBox("Write finger template successfully!");
return;
}
else
{
AfxMessageBox("Fail to write finger template!");
}
}
void CAuthentication::OnIcAuthenticate() //by limeihong 2002-8-14
{
// TODO: Add your control notification handler code here
int res;
//read finger template from IC card
CMbtoIC m_readic;
int cenx1,ceny1;
// unsigned char* length = new BYTE[1];
if(m_readic.ReadBinarytoMb(202,m_Minutia1)==0)
return;
cenx1 = (int)m_Minutia1[200];
ceny1 = (int)m_Minutia1[201];
// CCapTipDlg *pTipDlg;
// pTipDlg=new CCapTipDlg();
// pTipDlg->Create(IDD_TIP_DLG1);
// pTipDlg->ShowWindow(SW_SHOWNORMAL);
// (pTipDlg->GetDlgItem(IDC_TIP_TEXT))->SetWindowText("正在比对....");
res=FingerMatch(m_Minutia1,m_Minutia2,cenx1,ceny1,cenx2,ceny2);
// pTipDlg->EndDialog(1);
if(res>=theApp.m_nMatchDoor)
{
CDialog *pdlg=new CDialog();
pdlg->Create(IDD_MATCH_OK_DLG);
pdlg->ShowWindow(SW_SHOWNORMAL );
// MessageBox("两枚指纹相符合,身份认证成功!!!","结果",MB_OK);
}
else
{
CDialog *pdlg=new CDialog();
pdlg->Create(IDD_MATCH_NOT_DLG);
pdlg->ShowWindow(SW_SHOWNORMAL );
// MessageBox("两枚指纹不符,身份认证失败!","结果",MB_OK);
}
}
void CAuthentication::OnIcInquire() //连接的采集指纹和把指纹写到卡中
{
// TODO: Add your control notification handler code here
if(theApp.cap_type==1)//////////光电指纹采集仪采集图像/////////////////////
{
CScanDialog gfr(sbmp1);
if(gfr.DoModal()==IDOK)
{
if(!GetMinutia(sbmp1->m_Bmp_pBmpValue,NULL,sbmp1->m_Height,sbmp1->m_Width ,m_Minutia1,quli1,type1,cenx1,ceny1))
{
MessageBox("录取的指纹图像不合格","注意",MB_OK);
return;
}
RECT rc;
GetDlgItem(IDC_FINGER_BMP1)->GetWindowRect(&rc);
InvalidateRect(&rc);
}
}
else if(theApp.cap_type==2)/////////////电容传感器采集指纹图像////////////
{
CZhongzhGetBmp zz;
zz.GetBmp(sbmp1);
if(!GetMinutia(sbmp1->m_Bmp_pBmpValue,NULL,sbmp1->m_Height,sbmp1->m_Width ,m_Minutia1,quli1,type1,cenx1,ceny1))
{
MessageBox("录取的指纹图像不合格","注意",MB_OK);
return;
}
RECT rc;
GetDlgItem(IDC_FINGER_BMP1)->GetWindowRect(&rc);
InvalidateRect(&rc);
}
//以上程序为录取指纹特征值
OnWriteIc(); //写IC卡
}
void CAuthentication::OnIcMatch() //连接的采集指纹,从卡读指纹和比对
{
// TODO: Add your control notification handler code here
if(theApp.cap_type==1)//////////光电指纹采集仪采集图像/////////////////////
{
CScanDialog gfr(sbmp2);
if(gfr.DoModal()==IDOK)
{
if(!GetMinutia(sbmp2->m_Bmp_pBmpValue,NULL,sbmp2->m_Height,sbmp2->m_Width ,m_Minutia2,quli2,type2,cenx2,ceny2))
{
MessageBox("录取的指纹图像不合格","注意",MB_OK);
return;
}
RECT rc;
GetDlgItem(IDC_FINGER_BMP2)->GetWindowRect(&rc);
InvalidateRect(&rc);
}
}
else if(theApp.cap_type==2)/////////////电容传感器采集指纹图像////////////
{
CZhongzhGetBmp zz;
zz.GetBmp(sbmp2);
if(!GetMinutia(sbmp2->m_Bmp_pBmpValue,NULL,sbmp2->m_Height,sbmp2->m_Width ,m_Minutia2,quli2,type2,cenx2,ceny2))
{
MessageBox("录取的指纹图像不合格","注意",MB_OK);
return;
}
RECT rc;
GetDlgItem(IDC_FINGER_BMP2)->GetWindowRect(&rc);
InvalidateRect(&rc);
}
// //以上程序为录取指纹特征值
OnIcAuthenticate();
}
void CAuthentication::OnSetPort()
{
// TODO: Add your control notification handler code here
CFcom pcom;
if(pcom.DoModal()==IDOK)
{
theApp.finger_com = pcom.m_com;//输入串口值,缺省值为COM1
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -