vc++翻译成Delphi ( 积分: 200 )

  • 主题发起人 主题发起人 xaviter
  • 开始时间 开始时间
X

xaviter

Unregistered / Unconfirmed
GUEST, unregistred user!
static BOOL LoadMoban( const char* strFile, BYTE*& moban, int& moban_size )
{
FILE* fp = fopen( strFile, "rb" );
if (fp == 0)
return FALSE;
fseek( fp, 0L, SEEK_END );
moban_size = ftell( fp );
if (moban_size == 0) {
fclose( fp );
return FALSE;
}
moban = new BYTE[moban_size];
fseek( fp, 0L, SEEK_SET );
fread( moban, 1, moban_size, fp );
fclose( fp );
return TRUE;
}
static void UnloadMoban( BYTE* moban )
{
delete [] moban;
}
static BOOL SaveMoban( const char* strFile, const BYTE* moban, int moban_size )
{
FILE* fp = fopen( strFile, "wb" );
if (fp == 0)
return FALSE;
fwrite( moban, 1, moban_size, fp );
fclose( fp );
return TRUE;
}


// 位图保存
static void GenBmpColor( DWORD* pClr )
{
int i, n = 256;
BYTE* p;
for (i = 0; i < n; i++) {
p = (BYTE*) (pClr+i);
p[0] = i;
p[1] = i;
p[2] = i;
p[3] = 0;
}
}
static void GenBmpFileHeader( void* pBmpHeader, int nWidth, int nHeight, int nBit )
{
int nDataSize = nWidth * nHeight * nBit / 8; // Bytes
if (nWidth * nHeight * nBit % 8 != 0)
nDataSize++;

BITMAPFILEHEADER* pBmpFileHeader = (BITMAPFILEHEADER*) pBmpHeader;
pBmpFileHeader->bfType = *((WORD*)"BM");
pBmpFileHeader->bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + nDataSize;
pBmpFileHeader->bfReserved1 = 0;
pBmpFileHeader->bfReserved2 = 0;

pBmpFileHeader->bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
+ 1024;

BITMAPINFOHEADER* pBmpInfoHeader = (BITMAPINFOHEADER*) (pBmpFileHeader+1);
pBmpInfoHeader->biSize = sizeof(BITMAPINFOHEADER);
pBmpInfoHeader->biWidth = nWidth;
pBmpInfoHeader->biHeight = nHeight;
pBmpInfoHeader->biPlanes = 1;
pBmpInfoHeader->biBitCount = nBit;
pBmpInfoHeader->biCompression = 0;
pBmpInfoHeader->biSizeImage = nDataSize;
pBmpInfoHeader->biXPelsPerMeter = 0;
pBmpInfoHeader->biYPelsPerMeter = 0;

pBmpInfoHeader->biClrUsed = 256;
pBmpInfoHeader->biClrImportant = 0x21b0b;
}
static BOOL SaveBitmap( const char* strFile, const BYTE* Bitmap )
{
FILE* fp = fopen( strFile, "wb" );
if (fp) {
BYTE Header[256];
GenBmpFileHeader( Header, 640, 480, 8 );
fwrite( Header, sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER), 1, fp );

DWORD Color[256];
GenBmpColor( Color );
fwrite( Color, sizeof(DWORD), 256, fp );

fwrite( Bitmap, 1, 640*480, fp );

fclose( fp );
return TRUE;
}
return FALSE;
}


// TTS

/*
#include <sapi.h>
#pragma comment(lib,"sapi.lib")
ISpVoice* g_pVoice = NULL;
static bool TTS_initiate()
{
if (FAILED(::CoInitialize( NULL )))
return false;
HRESULT hr = CoCreateInstance( CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void**)&g_pVoice );
if (FAILED(hr))
return false;
return true;
}
static void TTS_speak( const WCHAR* text )
{
if (g_pVoice)
g_pVoice->Speak( text, 0, NULL );
}
static void TTS_release()
{
if (g_pVoice) {
g_pVoice->Release();
g_pVoice = NULL;
}
::CoUninitialize();
}
*/

// 回调函数
void EnrollCB( int enroll_info, const BYTE* moban_buf, int moban_size, const BYTE* bitmap_buf, int bitmap_size, int bitmap_num )
{
if (enroll_info == ENROLL_INFO_OK) {
char strFile[256];
sprintf( strFile, "%s//moban.dat", TEMP_DIR );
SaveMoban( strFile, moban_buf, moban_size );
int one_bitmap_size = bitmap_size / bitmap_num;
for (int i = 0; i < bitmap_num; i++) {
sprintf( strFile, "%s//bitmap_%d.bmp", TEMP_DIR, i+1 );
SaveBitmap( strFile, bitmap_buf+i*one_bitmap_size );
}
sprintf( strFile, "%s//moban.dat", TEMP_DIR );
UnloadMoban( g_pDlg->m_pMoban ); g_pDlg->m_pMoban = 0; g_pDlg->m_nMobanSize = 0;
if (LoadMoban( strFile, g_pDlg->m_pMoban, g_pDlg->m_nMobanSize )) {
g_pDlg->m_VerifyBtn.EnableWindow( TRUE );
//TTS_speak( L"注册成功!" );
} else {
g_pDlg->m_VerifyBtn.EnableWindow( FALSE );
//TTS_speak( L"保存注册数据失败!" );
}
} else if (ENROLL_INFO_CAOSHI) {
g_pDlg->m_VerifyBtn.EnableWindow( FALSE );
//TTS_speak( L"注册失败!" );
}
}
void VerifyCB( int verify_info )
{
/*
if (verify_info == VERIFY_INFO_OK)
TTS_speak( L"验证通过!" );
else if (verify_info == VERIFY_INFO_INV)
TTS_speak( L"验证未通过!" );
else if (verify_info == VERIFY_INFO_CAOSHI)
TTS_speak( L"验证超时!" );
*/
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIRIS_testDlg dialog

CIRIS_testDlg::CIRIS_testDlg(CWnd* pParent /*=NULL*/)
: CDialog(CIRIS_testDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CIRIS_testDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CIRIS_testDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CIRIS_testDlg)
DDX_Control(pDX, IDC_BUTTON_VERIFY, m_VerifyBtn);
DDX_Control(pDX, IDC_BUTTON_ENROLL, m_EnrollBtn);
DDX_Control(pDX, IDC_EDIT_SHOW, m_ShowCtrl);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CIRIS_testDlg, CDialog)
//{{AFX_MSG_MAP(CIRIS_testDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_ENROLL, OnButtonEnroll)
ON_BN_CLICKED(IDC_BUTTON_VERIFY, OnButtonVerify)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIRIS_testDlg message handlers

BOOL CIRIS_testDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
g_pDlg = this;
m_pMoban = 0;
m_nMobanSize = 0;
m_VerifyBtn.EnableWindow( FALSE );
char strFile[256];
sprintf( strFile, "%s//moban.dat", TEMP_DIR );
if (LoadMoban( strFile, m_pMoban, m_nMobanSize )) {
m_VerifyBtn.EnableWindow( TRUE );
}
int ret = IRIS_initiate( m_ShowCtrl.GetSafeHwnd() );
if (ret == IRIS_ERR_LIC) {
MessageBox( "引擎未注册!" );
exit(-1);
} else if (ret != IRIS_OK) {
MessageBox( "引擎初始化失败!" );
exit(-1);
}
// if (! TTS_initiate())
// MessageBox( "TTS不可用!" );
// else
// TTS_speak( L"欢迎使用!" );
mkdir( TEMP_DIR );
return TRUE; // return TRUE unless you set the focus to a control
}

void CIRIS_testDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CIRIS_testDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CIRIS_testDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CIRIS_testDlg::OnDestroy()
{
CDialog::OnDestroy();

// TODO: Add your message handler code here
IRIS_release();
//TTS_release();
UnloadMoban( m_pMoban ); m_pMoban = 0; m_nMobanSize = 0;
}

void CIRIS_testDlg::OnButtonEnroll()
{
// TODO: Add your control notification handler code here
if (IRIS_OK != IRIS_enroll( EnrollCB ))
MessageBox( "注册启动失败!" );
}

void CIRIS_testDlg::OnButtonVerify()
{
// TODO: Add your control notification handler code here
if (IRIS_OK != IRIS_verify( m_pMoban, m_nMobanSize, VerifyCB ))
MessageBox( "验证启动失败!" );
}
 

Similar threads

I
回复
0
查看
724
import
I
I
回复
0
查看
729
import
I
I
回复
0
查看
844
import
I
I
回复
0
查看
658
import
I
后退
顶部