www.pudn.com > fingerprint.rar > FingerPrint.cpp


// FingerPrint.cpp : Defines the entry point for the application. 
// 
 
#include "stdafx.h" 
#include "resource.h" 
#include "dibapi.h" 
#include "types.h" 
#include "math.h" 
 
#define MAX_LOADSTRING 100 
 
// Global Variables: 
HINSTANCE hInst;								// current instance 
TCHAR szTitle[MAX_LOADSTRING];								// The title bar text 
TCHAR szWindowClass[MAX_LOADSTRING];								// The title bar text 
 
 
HDIB hMatch=NULL; 
HDIB hTemplate=NULL; 
FINGER_PRINT fpMatch; 
FINGER_PRINT fpTemplate; 
 
static const SIZE defaultsize={256,256}; 
 
// Foward declarations of functions included in this code module: 
ATOM				fpRegisterClass(HINSTANCE hInstance); 
BOOL				fpInitInstance(HINSTANCE, int); 
LRESULT CALLBACK	fpWndProc(HWND, UINT, WPARAM, LPARAM); 
LRESULT CALLBACK	fpAbout(HWND, UINT, WPARAM, LPARAM); 
 
int APIENTRY WinMain(HINSTANCE hInstance, 
                     HINSTANCE hPrevInstance, 
                     LPSTR     lpCmdLine, 
                     int       nCmdShow) 
{ 
 	// TODO: Place code here. 
	MSG msg; 
	HACCEL hAccelTable; 
 
	// Initialize global strings 
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 
	LoadString(hInstance, IDC_FINGERPRINT, szWindowClass, MAX_LOADSTRING); 
	fpRegisterClass(hInstance); 
 
	// Perform application initialization: 
	if (!fpInitInstance (hInstance, nCmdShow))  
	{ 
		return FALSE; 
	} 
 
	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_FINGERPRINT); 
 
	// Main message loop: 
	while (GetMessage(&msg, NULL, 0, 0))  
	{ 
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))  
		{ 
			TranslateMessage(&msg); 
			DispatchMessage(&msg); 
		} 
	} 
 
	return msg.wParam; 
} 
 
 
 
// 
//  FUNCTION: MyRegisterClass() 
// 
//  PURPOSE: Registers the window class. 
// 
//  COMMENTS: 
// 
//    This function and its usage is only necessary if you want this code 
//    to be compatible with Win32 systems prior to the 'RegisterClassEx' 
//    function that was added to Windows 95. It is important to call this function 
//    so that the application will get 'well formed' small icons associated 
//    with it. 
// 
ATOM fpRegisterClass(HINSTANCE hInstance) 
{ 
	WNDCLASSEX wcex; 
 
	wcex.cbSize = sizeof(WNDCLASSEX);  
 
	wcex.style			= CS_HREDRAW | CS_VREDRAW; 
	wcex.lpfnWndProc	= (WNDPROC)fpWndProc; 
	wcex.cbClsExtra		= 0; 
	wcex.cbWndExtra		= 0; 
	wcex.hInstance		= hInstance; 
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_FINGERPRINT); 
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW); 
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1); 
	wcex.lpszMenuName	= (LPCSTR)IDC_FINGERPRINT; 
	wcex.lpszClassName	= szWindowClass; 
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); 
 
	return RegisterClassEx(&wcex); 
} 
 
// 
//   FUNCTION: InitInstance(HANDLE, int) 
// 
//   PURPOSE: Saves instance handle and creates main window 
// 
//   COMMENTS: 
// 
//        In this function, we save the instance handle in a global variable and 
//        create and display the main program window. 
// 
BOOL fpInitInstance(HINSTANCE hInstance, int nCmdShow) 
{ 
   HWND hWnd; 
 
   hInst = hInstance; // Store instance handle in our global variable 
 
   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 
      CW_USEDEFAULT, 0, defaultsize.cx , defaultsize.cy , NULL, NULL, hInstance, NULL); 
 
   if (!hWnd) 
   { 
      return FALSE; 
   } 
 
   ShowWindow(hWnd, nCmdShow); 
   UpdateWindow(hWnd); 
 
   return TRUE; 
} 
//////绘制采样点 
static void PaintPoint(HDC hdc,int x,int y,COLORREF c) 
{ 
	POINT pt; 
//	SetPixel(hdc,x,y,c); 
	MoveToEx(hdc,x-1,y-1,&pt); 
	LineTo(hdc,x-1,y+1); 
	LineTo(hdc,x+1,y+1); 
	LineTo(hdc,x+1,y-1 ); 
	LineTo(hdc,x-1,y-1 ); 
 
} 
//////绘制指纹 
void fpPaintFingerPrint(HDC hdc,HDIB hDIB ,FINGER_PRINT&fp,RECT& rt,RECT&rcDIB,COLORREF c) 
{ 
	POINT pt;int dx,dy; 
	::PaintDIB(hdc, &rt, hDIB,&rcDIB, NULL); 
	HANDLE hPen=CreatePen(PS_SOLID,0,c); 
	HANDLE hOld=SelectObject(hdc,hPen); 
	///细节点与采样点 
	for(int i=0;i