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

📄 zktestdlg.cpp

📁 一个简单的字库测试程序
💻 CPP
字号:
// zkTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "zkTest.h"
#include "zkTestDlg.h"
#include "memory.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

unsigned char cSourceBuff[72*94*3];


/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CZkTestDlg dialog

CZkTestDlg::CZkTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CZkTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CZkTestDlg)
		// 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 CZkTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CZkTestDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CZkTestDlg, CDialog)
	//{{AFX_MSG_MAP(CZkTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_buttSee, OnbuttSee)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZkTestDlg message handlers

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

	HANDLE  hOpen;	// 于汉字库相关
	DWORD	uAct;
	char	cActSize[5];	


	// 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
		/* 打开文件 */
	hOpen = CreateFile( "c:\\biaodian.bin", GENERIC_READ, FILE_SHARE_READ, NULL,
						OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL );
	if( hOpen == INVALID_HANDLE_VALUE )
	{
		MessageBox( "没有数据库", "警告", MB_OK );
		// 销毁当前窗口
		::SendMessage( this->m_hWnd, WM_CLOSE, 0, 0 );
		return FALSE;
	}

	memset( cSourceBuff, 0, 72*94*3 );

	/* 读数据 */
	ReadFile( hOpen, cSourceBuff, 72*94*3, &uAct, NULL );

	CloseHandle( hOpen );

	memset( cActSize, 0, 5 );
	sprintf( cActSize, "%d", uAct/72 );
	MessageBox( cActSize, "当前库大小", MB_OK );

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

void CZkTestDlg::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 CZkTestDlg::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 CZkTestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

// 得到偏移量
int CZkTestDlg::GetCodeOffset( unsigned short iCode )
{
	//  定义
	unsigned char uQu, uWei;	//  区位码

	uQu  = ( iCode >> 8 ) & 0x00ff - 0xa0;
	uWei = ( iCode & 0x00ff ) - 0xa0;

	if( uQu < 4 && uQu > 0 && uWei > 0 && uWei < 95 )
		return ((uQu-1) * 94 + (uWei-1))*72;
	else
	{
		MessageBox( "码值不对!", "错误", MB_OK );
		return -1;
	}
}

// 获得输入内码并得到对应的字模偏移,调用显示
void CZkTestDlg::OnbuttSee() 
{
	int iOffset;
	char cText[3];
	unsigned short uIncode;

	// 从文本框中得到字符的内码字符串
	memset( cText, 0, 3 );
	GetDlgItemText( IDC_EDIT1, cText, 3 );
	
	if( strlen( cText ) == 0 )
	{
		MessageBox( "请输入内码", "Error", MB_OK );
		return;
	}
	uIncode = 0;
	uIncode = /*0xa1a3;*/((unsigned char)cText[0] * 256) + (unsigned char)cText[1];
	// 得到字符的内码
	iOffset = this->GetCodeOffset( uIncode );

	if( iOffset == -1 )	// 内码错误
		return;

	// 打印(画出)内码
	this->DrawTheMode( iOffset );

	return;
}

// 回画
void CZkTestDlg::UnDraw()
{
	CDC *pDC;

	CPen cPen;
	CBrush cBrush;
	pDC = GetDC();
	cPen.CreatePen( 0, 0, RGB(255, 255, 255) );
	cBrush.CreateSolidBrush( RGB(255, 255, 255) );
	pDC->SelectObject( cPen );
	pDC->SelectObject( cBrush );
	pDC->Rectangle( 50, 50, 50 + 24, 50 + 24 );
	ReleaseDC( pDC );

	return;
}

// 显示字模
void CZkTestDlg::DrawTheMode( int iOffset )
{
	int iOffsetLoop;
	unsigned char uBitCount, cBit2Draw;
	int iStartX, iStartY;

	// 得到图形句柄
	CDC *pDC;
	pDC = GetDC();

	// 重绘
	this->UnDraw();

	// 绘出字模
	iStartX		= 50;
	iStartY		= 50;
	uBitCount	= 0;
	for( iOffsetLoop = iOffset; iOffsetLoop < iOffset+72; )
	{
		// 确定位置
		if( iStartX >= 50 + 24 )
		{
			iStartX = 50;
			iStartY ++;
		}

		// 字节对齐
		if( uBitCount > 7 )
		{
			uBitCount = 0;
			iOffsetLoop++;
		}

		// 得到一字节的字模
		cBit2Draw = ( cSourceBuff[iOffsetLoop] >> (7-uBitCount) ) & 0x01;


		// 绘出该点
		if( cBit2Draw )
		{
			pDC->SetPixel( iStartX, iStartY, RGB(0, 0, 0) );
		}		
		
		uBitCount++;
		iStartX++;

	}

	return;
}

⌨️ 快捷键说明

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