Windows 指纹(Finger print)设备设别测试软件

#include <Stdio.h>
#include <Conio.h>
#include <Winbio.h>

#pragma comment(lib, "Winbio.lib")

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                
WCHAR szTitle[MAX_LOADSTRING];                  
WCHAR szWindowClass[MAX_LOADSTRING];            
int flag = 0;
HWND hEdit;  // to handle the text box show the message

ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);

HRESULT  WINAPI  EnrollSysPool(LPVOID)
{

	BOOL discardEnrollment = false;
	WINBIO_BIOMETRIC_SUBTYPE subFactor = WINBIO_FP_TOO_HIGH;
	HRESULT hr = S_OK;
	WINBIO_IDENTITY identity = { 0 };
	WINBIO_SESSION_HANDLE sessionHandle = NULL;
	WINBIO_UNIT_ID unitId = 0;
	WINBIO_REJECT_DETAIL rejectDetail = 0;
	BOOLEAN isNewTemplate = TRUE;

	// Connect to the system pool. 
	hr = WinBioOpenSession(	WINBIO_TYPE_FINGERPRINT, WINBIO_POOL_SYSTEM, WINBIO_FLAG_DEFAULT, NULL, 0, NULL, &sessionHandle);
	if (FAILED(hr))
	{
		SetWindowText(hEdit, L"\n WinBioOpenSession failed. ");
		goto e_Exit;
	}

	// Locate a sensor.
	SetWindowText(hEdit, L"Swipe your finger on the sensor...");
	hr = WinBioLocateSensor(sessionHandle, &unitId);
	if (FAILED(hr))
	{
		SetWindowText(hEdit, L"WinBioLocateSensor failed.");
		goto e_Exit;
	}

	// Begin the enrollment sequence. 
	SetWindowText(hEdit, L"Starting enrollment sequence...");
	hr = WinBioEnrollBegin(sessionHandle, subFactor, unitId/* Biometric unit ID */);
	if (FAILED(hr))
	{
		SetWindowText(hEdit, L"WinBioEnrollBegin failed.");
		goto e_Exit;
	}

	for (int swipeCount = 1;; ++swipeCount)
	{
		if(swipeCount == 1)	SetWindowText(hEdit, L"Swipe the sensor to capture the first sample");

		hr = WinBioEnrollCapture(sessionHandle, &rejectDetail   );
		if (swipeCount >= 3) {
			hr = WinBioEnrollDiscard(sessionHandle);
			if (FAILED(hr))
			{
				SetWindowText(hEdit, L"WinBioLocateSensor failed.");
			}
			WinBioCloseSession(sessionHandle);
			exit(0);
		}

		WCHAR buf[90];
		wsprintf(buf, L"Sample %d captured from unit %d.", swipeCount, unitId);
		SetWindowText(hEdit, buf);

		if (hr == WINBIO_I_MORE_DATA)
		{
			SetWindowText(hEdit, L"More data required");
			continue;
		}
		if (FAILED(hr))
		{
			if (hr == WINBIO_E_BAD_CAPTURE)
			{
				SetWindowText(hEdit, L"................Error: Bad capture");
				continue;
			}
			else
			{
				SetWindowText(hEdit, L"WinBioEnrollCapture failed.");
				goto e_Exit;
			}
		}
		else
		{
			SetWindowText(hEdit, L"Template completed.");
			break;
		}
	}

	// Discard the enrollment or commit
	if (discardEnrollment == TRUE)
	{
		SetWindowText(hEdit, L"Discarding enrollment");
		hr = WinBioEnrollDiscard(sessionHandle);
		if (FAILED(hr))
		{
			SetWindowText(hEdit, L"WinBioLocateSensor failed.");
		}
		goto e_Exit;
	}
	else
	{
		SetWindowText(hEdit, L"Committing enrollment...");
		hr = WinBioEnrollCommit(sessionHandle, &identity, &isNewTemplate);
		if (FAILED(hr))
		{
			SetWindowText(hEdit, L"WinBioEnrollCommit failed.");
			goto e_Exit;
		}
	}

e_Exit:
	if (sessionHandle != NULL)
	{
		WinBioCloseSession(sessionHandle);
		sessionHandle = NULL;
	}

	return hr;
}

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,  _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine,  _In_ int  nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.

    // Initialize global strings
    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadStringW(hInstance, IDC_WFINGER, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }


	HANDLE hThread;
	DWORD  threadId;
	/*create a thread to deal with finger swap*/
	hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)EnrollSysPool, 0, 0, &threadId); 

	MSG msg;

    while (GetMessage(&msg, nullptr, 0, 0))
    {
        if (!TranslateAcceleratorW(msg.hwnd, 0, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}


ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEXW wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDC_WFINGER));
    wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassExW(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; 

   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPED | WS_CAPTION |  WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX, CW_USEDEFAULT, 0, 600, 300, nullptr, nullptr, hInstance, nullptr);

   hEdit = CreateWindowExW(0, L"EDIT", L"Test windows", WS_CHILD | WS_VISIBLE | WS_BORDER, 20, 60, 500, 30, hWnd, 0, 0, 0);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
		case WM_COMMAND:
		    {
		        int wmId = LOWORD(wParam);
		        // Parse the menu selections:
		        switch (wmId)
		        {
					case 0:
						break;
					default:
						return DefWindowProc(hWnd, message, wParam, lParam);
		        }
		    }
		    break;
		case WM_PAINT:
		    {
		        PAINTSTRUCT ps;
		        HDC hdc = BeginPaint(hWnd, &ps);
		        // TODO: Add any drawing code that uses hdc here...
		        EndPaint(hWnd, &ps);
		    }
		    break;
		case WM_CLOSE:
			MessageBox(hWnd, L"You can not do this!", L"Error", MB_ICONERROR);
		    break;
		default:
		    return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值