chinesedlg.cpp

来自「嵌入式汉字输入法及汉字库设计,点阵字库,精简的数据结构,高效的4键输入法」· C++ 代码 · 共 410 行

CPP
410
字号
// chineseDlg.cpp : implementation file
//

#include "stdafx.h"
#include "chinese.h"
#include "chineseDlg.h"
#include "pinyin.h"
#include "Fhzk16x16gui.h"
#include "stdio.h"
#include "math.h"

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

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

/////////////////////////////////////////////////////////////////////////////
// CChineseDlg dialog

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

BEGIN_MESSAGE_MAP(CChineseDlg, CDialog)
	//{{AFX_MSG_MAP(CChineseDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChineseDlg message handlers

BOOL CChineseDlg::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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

//求国标
void CChineseDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
/*
	unsigned short gb;
	unsigned char *pchar;
	pchar =(unsigned char *)(&PY_mb_bian[2]);
	gb = (((unsigned short) *(pchar+1))<<8) + (*pchar);
*/
}

//汉字转.bin文件
void CChineseDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
/*
	FILE *pFile,*pFile2,*pFile3;
	int	i,pPoint,len;

	pPoint=0;
	pFile3 = fopen("zpzk333.bin","ab+");
	pPoint = 226056;

	pFile = fopen("hanzi.bin","wb");
	pFile2 = fopen("temp.cpp","w");
	char kong=0;

	fprintf(pFile2,"MyPyNode[]={\n");
	fseek(pFile,0,0);
	for(i=0;i<407;i++)
	{		
		len = strlen(MyPyNode[i].pHanZi);
		fwrite(MyPyNode[i].pHanZi,1,len,pFile3);
		fwrite(&kong,1,1,pFile3);
		fprintf(pFile2,"{%d,##",pPoint);
		fprintf(pFile2,MyPyNode[i].Pinyin);
		fprintf(pFile2,"##},\n");
		pPoint+=len+1;
	}
	fprintf(pFile2,"};\n");
	fclose(pFile);
	fclose(pFile2);
	fclose(pFile3);
*/
}


//遍历四叉树

void  PreOderTraverse(PY_LINK * root)
{
	PY_LINK *p;
	unsigned long pHanzi;
	char *pPy;
	unsigned short *pNode;
	//================取节点值=====================
	p = root;
	if(p != NULL)
	{
		if(p->pPyNode != NULL)
		{
			pNode = p->pPyNode;
			while(*pNode != 9999)
			{
				pHanzi = MyPyNode[*pNode].ulHanZi;
				pPy = MyPyNode[*pNode].Pinyin;
				pNode++;
			}
		}
	}
	//=============================================
	if(p != NULL)
	{
		PreOderTraverse(p->pSon[0]);
		PreOderTraverse(p->pSon[1]);
		PreOderTraverse(p->pSon[2]);
		PreOderTraverse(p->pSon[3]);
	}	
}
/**/

void CChineseDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	
	int code,k,i,len;
	char str[7]="1132";
	char buff[50];
	PY_LINK *pLinkHead;
	pLinkHead = &LinkOne[0];

	code =0;
	strcpy(buff,str);
	len = strlen(str);
	//得到一棵子树
	if(len<7)
	{
		for(i=0;i<len;i++)
		{
			k=((int) buff[i])-0x30;
			if(k<5)
			{
				pLinkHead = pLinkHead->pSon[k-1];
			}		
		}
	}
		//遍历此子树
	PreOderTraverse(pLinkHead);
/**/
}


//按键操作处理
PY_LINK link;

typedef struct{
	unsigned short start;		//国标区段的起点值  []
	unsigned short end;			//国标区段的综点值
	unsigned short Index;		//起点值对应的字模存储位置,以32字节为单位 Index*32
}S_LINK_T;

void CChineseDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	FILE *pFile;
	S_LINK_T p;
	int i,j,k,pPoint;
	int num=0;
	int pFilePoint;
	unsigned short index;		//MyPyNode[]数组下标
	CString	MyCString;			//VC的一个类用于字符串的格式化
	char keynew[7]={1,1,3,2,5,2,3};
	char key[7];
	char guobiao[20];
	char Data[500];
	unsigned short gb,gb1;
	//unsigned short guobiao[50];
	unsigned long AddrOffset[50];
	unsigned long keynum;
	unsigned long temp;

	keynum = 0;

	pFile = fopen("zpzk333.bin","r");
	pPoint = 226056;

	for(i=0;i<7;i++)
	{
		key[i] = keynew[i];
		if(keynew[i] == 5)
		{
			break;
		}
	}
	for(j=0;j<i;j++)
	{
		temp = (unsigned long)pow((double)10,(double)(i-1-j));
		keynum += key[j]*temp;
	}

	MyCString.Format("PYNode%d",keynum);
	
	for(i=0;i<10;i++)
	{
		if(MyCString[i] != 9999)
		{
			index = (unsigned short)MyCString[i];
			AddrOffset[i] = MyPyNode[index].ulHanZi;
			//guobiao[i]= (unsigned short)(&MyPyNode[index].Pinyin);
		}
		else
		{
			break;
		}
	}
	for(j=0;j<i;j++)
	{
		pPoint=AddrOffset[j];
		fseek(pFile,pPoint,0);
		fread((&guobiao[j*2]),8,2,pFile);
	}

	pFilePoint = 225600;
	fseek(pFile,pFilePoint,0);
	fread((void*)&p,2,3,pFile);
	pFilePoint+=6;

	for(j=0;j<10;j++)
	{
		gb = ((unsigned short)(guobiao[j*2]<<8))+(unsigned char) guobiao[j*2+1];
		while(1)
		{
			if(gb>=p.start && gb<=p.end)
			{
				k += gb - p.start + p.Index;
				k *= 32;
				fseek(pFile,k,0);
				fread((void*)Data,4,8,pFile);
				break;
			}
			else
			{
				num++;
				if(num>75)
				{
					break;
				}
				fseek(pFile,pFilePoint,0);
				fread((void*) &p,2,3,pFile);
				pFilePoint +=6;
			}
		}
	}





}

//用于测试
void CChineseDlg::OnButton5() 
{
	// TODO: Add your control notification handler code here
	char guobiao[2]={0x33,0x22};
	short gb;
	gb = (guobiao[0]<<8) | guobiao[1];
}

⌨️ 快捷键说明

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