⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enrollmentdlg.cpp

📁 DigitalPersona.rar
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SampleRegDlg.cpp : implementation file
//
#include "stdafx.h"
#include "EnrollmentDlg.h"
#include "Utilities.h"
#include "dpFtrEx.h"
#include "dpMatch.h"

/**************************************************************************************************
                                Sample code for Fingerprint Enrollment
                                Copyright Digital Persona, Inc. 1996-2007
/*************************************************************************************************/

/////////////////////////////////////////////////////////////////////////////
// CEnrollmentDlg dialog

CEnrollmentDlg::CEnrollmentDlg() : 
	CDialogImpl<CEnrollmentDlg>(), 
	m_hOperationEnroll(0),
	m_fxContext(0),
	m_mcContext(0),
	m_TemplateArray(NULL),
	m_nRegFingerprint(0),
	m_mcRegOptions(FT_DEFAULT_REG)
{
	::ZeroMemory(&m_rcDrawArea, sizeof(m_rcDrawArea));
	::ZeroMemory(&m_RegTemplate, sizeof(m_RegTemplate));
}

CEnrollmentDlg::~CEnrollmentDlg() {
	delete [] m_RegTemplate.pbData;
	m_RegTemplate.cbData = 0;
	m_RegTemplate.pbData = NULL;
}

void CEnrollmentDlg::GetRegTemplate(DATA_BLOB& rRegTemplate) const {
	if (m_RegTemplate.cbData && m_RegTemplate.pbData) { // only copy template if it is not empty
		// Delete the old stuff that may be in the template.
		delete [] rRegTemplate.pbData;
		rRegTemplate.pbData = NULL;
		rRegTemplate.cbData = 0;

		// Copy the new template, but only if it has been created.
		rRegTemplate.pbData = new BYTE[m_RegTemplate.cbData];
		if (!rRegTemplate.pbData) _com_issue_error(E_OUTOFMEMORY);
		::CopyMemory(rRegTemplate.pbData, m_RegTemplate.pbData, m_RegTemplate.cbData);
		rRegTemplate.cbData = m_RegTemplate.cbData;
	}
}

void CEnrollmentDlg::AddStatus(LPCWSTR s) {
	int lIdx = SendDlgItemMessage(IDC_STATUS, LB_ADDSTRING, 0, (LPARAM)s);
	SendDlgItemMessage(IDC_STATUS, LB_SETTOPINDEX, lIdx, 0);
}

LRESULT CEnrollmentDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	HRESULT hr = S_OK;
	try {
		FT_RETCODE rc = FT_OK;

		// Create Context for Feature Extraction
		if (FT_OK != (rc = FX_createContext(&m_fxContext))) {
			MessageBox(L"Cannot create Feature Extraction Context.", L"Fingerprint Enrollment", MB_OK | MB_ICONSTOP);
			_com_issue_error(E_FAIL);
		}

		// Create Context for Matching
		if (FT_OK != (rc = MC_createContext(&m_mcContext))) {
			MessageBox(L"Cannot create Matching Context.", L"Fingerprint Enrollment", MB_OK | MB_ICONSTOP);
			_com_issue_error(E_FAIL);
		}

		// Get number of Pre-Enrollment feature sets needed to create on Enrollment template
		// allocate array that keeps those Pre-Enrollment and set the first index to 0;
		MC_SETTINGS mcSettings = {0};
		if (FT_OK != (rc = MC_getSettings(&mcSettings))) {
			MessageBox(L"Cannot get number of Pre-Reg feature sets needed to create one Enrollment template.", L"Fingerprint Enrollment", MB_OK | MB_ICONSTOP);
			_com_issue_error(E_FAIL);
		}

		m_NumberOfPreRegFeatures = mcSettings.numPreRegFeatures;
		if (NULL == (m_TemplateArray = new FT_BYTE*[m_NumberOfPreRegFeatures]))
			_com_issue_error(E_OUTOFMEMORY);

		::ZeroMemory(m_TemplateArray, sizeof(FT_BYTE**)*m_NumberOfPreRegFeatures);

		m_nRegFingerprint = 0;  // This is index of the array where the first template is put.


		// Get area of the fingerprint image on the screen from the helper control
		::GetWindowRect(GetDlgItem(IDC_STATIC_DRAWAREA_SIZE), &m_rcDrawArea);

		// Start Enrollment.
		DP_ACQUISITION_PRIORITY ePriority = DP_PRIORITY_NORMAL; // Using Normal Priority, i.e. fingerprint will be sent to 
											  // this process only if it has active window on the desktop.
		_com_test_error(DPFPCreateAcquisition(ePriority, GUID_NULL, DP_SAMPLE_TYPE_IMAGE, m_hWnd, WMUS_FP_NOTIFY, &m_hOperationEnroll));
		_com_test_error(DPFPStartAcquisition(m_hOperationEnroll));

		SetDlgItemText(IDC_EDIT_PROMPT, L"Scan your finger for enrollment.");
	}
	catch(_com_error& E) {
		hr = E.Error();
	}
	catch(...) {
		hr = E_UNEXPECTED;
	}

	if (FAILED(hr)) {
		SetDlgItemText(IDC_EDIT_PROMPT, L"Error happened");
		ReportError(m_hWnd, hr);
		EndDialog(IDCANCEL);
	}

	return TRUE;  // return TRUE  unless you set the focus to a control
}

LRESULT CEnrollmentDlg::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	if (m_hOperationEnroll) {
		DPFPStopAcquisition(m_hOperationEnroll);    // No error checking - what can we do at the end anyway?
		DPFPDestroyAcquisition(m_hOperationEnroll);
		m_hOperationEnroll = 0;
	}

	if (m_fxContext) {
		FX_closeContext(m_fxContext);
		m_fxContext = 0;
	}

	if (m_mcContext) {
		MC_closeContext(m_mcContext);
		m_mcContext = 0;
	}

	if(m_TemplateArray){
		for (int i=0; i<m_NumberOfPreRegFeatures; ++i)
			if(m_TemplateArray[i]) delete [] m_TemplateArray[i], m_TemplateArray[i] = NULL; // Delete Pre-Enrollment feature sets stored in the array.
		
		delete [] m_TemplateArray; // delete the array itself.
		m_TemplateArray = NULL;
	}

	return 0;
}

LRESULT CEnrollmentDlg::OnFpNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
	switch(wParam) {
		case WN_COMPLETED: {
	        AddStatus(L"Fingerprint image captured");
			DATA_BLOB* pImageBlob = reinterpret_cast<DATA_BLOB*>(lParam);

			// Display fingerprint image
			DisplayFingerprintImage(pImageBlob->pbData);

			// Add fingerprint image to the Enrollment
			AddToEnroll(pImageBlob->pbData, pImageBlob->cbData);
			break;
		}
		case WN_ERROR: {
			WCHAR buffer[101] = {0};
			_snwprintf(buffer, 100, L"Error happened. Error code: 0x%X", lParam);
	        AddStatus(buffer);
			break;
		}
		case WN_DISCONNECT:
	        AddStatus(L"Fingerprint reader disconnected");
			break;
		case WN_RECONNECT:
	        AddStatus(L"Fingerprint reader connected");
			break;
		case WN_FINGER_TOUCHED:
	        AddStatus(L"Finger touched");
			break;
		case WN_FINGER_GONE:
	        AddStatus(L"Finger gone");
			break;
		case WN_IMAGE_READY:
	        AddStatus(L"Fingerprint image ready");
			break;
		case WN_OPERATION_STOPPED:
	        AddStatus(L"Fingerprint Enrollment Operation stopped");
			break;
	}
	return 0;
}

LRESULT CEnrollmentDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	EndDialog(wID);
	return 0;
}

//LRESULT CEnrollmentDlg::OnModeCheckBox(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -