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

📄 winsorthzdlg.cpp

📁 汉字字模提取程序,自动生成C语言字库,自己编写的,有用的着的可以用一下,需要UCDOS的字库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// WinSortHzDlg.cpp : implementation file
//

#include "stdafx.h"
#include "WinSortHz.h"
#include "WinSortHzDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CWinSortHzDlg dialog

CWinSortHzDlg::CWinSortHzDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWinSortHzDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWinSortHzDlg)
	m_OpenFile = _T("C:\\Documents and Settings\\LEKY\\My Documents\\aaa.txt");
	m_ToFile = _T("C:\\Documents and Settings\\LEKY\\My Documents\\bbb.h");
	m_hzLibDir = _T("D:\\HZK\\");
	m_fontSel = _T("宋体");
	m_dianzhenSel = _T("16");
	m_position = 0;
	m_byteNum = 32;
	m_rows = 16;
	m_hzNum = 0;
	m_bDisplay = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_pMemDC = NULL;
	m_pOldBmp = NULL;
}

void CWinSortHzDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWinSortHzDlg)
	DDX_Control(pDX, IDC_BROWSELIB, m_browseLibButton);
	DDX_Text(pDX, IDC_OPENFILE, m_OpenFile);
	DDX_Text(pDX, IDC_TOFILE, m_ToFile);
	DDX_Text(pDX, IDC_HZLIBDIR, m_hzLibDir);
	DDX_CBString(pDX, IDC_FONT, m_fontSel);
	DDX_CBString(pDX, IDC_DIANZHEN, m_dianzhenSel);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CWinSortHzDlg, CDialog)
	//{{AFX_MSG_MAP(CWinSortHzDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BROWSE1, OnBrowse1)
	ON_BN_CLICKED(IDC_BROWSE2, OnBrowse2)
	ON_WM_DESTROY()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_DISPLAY, OnDisplay)
	ON_BN_CLICKED(IDC_HZLIB, OnHzlib)
	ON_BN_CLICKED(IDC_PREDISPLAY, OnPredisplay)
	ON_BN_CLICKED(IDC_BROWSELIB, OnBrowselib)
	ON_BN_CLICKED(IDC_ASCII, OnAscii)
	ON_BN_CLICKED(IDC_CREATECARRY, OnCreateCarry)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWinSortHzDlg message handlers

BOOL CWinSortHzDlg::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
	InitOutput();
	m_logfont.lfHeight=FALSE;
	m_logfont.lfWidth=0;
	m_logfont.lfEscapement=0;
	m_logfont.lfWeight=FW_NORMAL;
	m_logfont.lfItalic=FALSE;
	m_logfont.lfUnderline=FALSE;
	m_logfont.lfStrikeOut=FALSE;
	m_logfont.lfCharSet=GB2312_CHARSET;
	m_logfont.lfOutPrecision=OUT_STROKE_PRECIS;
	m_logfont.lfClipPrecision=CLIP_STROKE_PRECIS;
	m_logfont.lfQuality=DRAFT_QUALITY;
	m_logfont.lfPitchAndFamily=VARIABLE_PITCH|FF_MODERN;
	strcpy(m_logfont.lfFaceName,"仿宋_GB2312");

//	SetTimer(1, 200, NULL);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CWinSortHzDlg::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 CWinSortHzDlg::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
	{
		m_pDC->BitBlt(m_rect.left,m_rect.top,m_rect.right,m_rect.bottom,m_pMemDC,0,0,SRCCOPY);

		CDialog::OnPaint();
	}
}

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

void CWinSortHzDlg::OnBrowse1() 
{
	// TODO: Add your control notification handler code here
	CFileDialog openDlg(TRUE);
	if(openDlg.DoModal() == IDOK)
	{
		m_OpenFile = openDlg.GetPathName();
	}
	UpdateData(FALSE);		
}

void CWinSortHzDlg::OnBrowse2() 
{
	// TODO: Add your control notification handler code here
	CFileDialog toDlg(TRUE);
	if(toDlg.DoModal() == IDOK)
	{
		m_ToFile = toDlg.GetPathName();
	}
	UpdateData(FALSE);
}

void CWinSortHzDlg::OnOK() 
{

	// TODO: Add extra validation here
	UpdateData(TRUE);

/*************************************************
    文件读取过程
*************************************************/
	int i;
	int j;
	unsigned short hzint[5000];
	unsigned int length;
	m_sourceFile.Open(m_OpenFile, CFile::modeRead);
	length = m_sourceFile.GetLength();
    if(length > 5000)
	{
		length = 5000;
	}
	
	m_sourceFile.Read(hzint, length);
    m_sourceFile.Close();

/*************************************************
    排序
*************************************************/
	m_hzNum = length / 2;

    for(i=0; i<m_hzNum; i++)
    {
        for(j=i+1; j<m_hzNum; j++)
        {
            if(hzint[j] == hzint[i])
            {
                hzint[j] = hzint[m_hzNum-1];
                m_hzNum--;
                j--;
            }
        }
    }
	int last = m_hzNum - 1; 
    int sorted;
	unsigned int temp;
	do
    {
        sorted = 1;
        for(i=0; i<last; i++)
        {
            if(hzint[i] > hzint[i+1])
            {
                temp = hzint[i];
                hzint[i] = hzint[i+1];
                hzint[i+1] = temp;
                sorted = 0;
            }
        }
        last--;
    }while(sorted == 0);

/*************************************************
    排序后文件写入文件
*************************************************/
    CString str;
	m_targetFile.Open(m_ToFile, CFile::modeCreate|CFile::modeWrite);
	m_targetFile.WriteString("#define MAXCHINESENO  ");
	str.Format("%d\n\n", m_hzNum);
	m_targetFile.WriteString(str);
	m_targetFile.WriteString("//");
	m_targetFile.Write(hzint, m_hzNum*2);
	m_targetFile.WriteString("\ncode unsigned int chineseIndexOrg[] = { \n");
    for(i=0; i<m_hzNum; i++)
	{
		if(i==m_hzNum-1)
		{
			str.Format("\n\t0x%04X \t\t\t//", hzint[i]);
		}
		else
		{
			str.Format("\n\t0x%04X,\t\t\t//", hzint[i]);
		}
		m_targetFile.WriteString(str);
		m_targetFile.Write(&hzint[i], 2);
	}
	m_targetFile.WriteString("\n\t\t};\n");

/*************************************************
    点阵数组写入文件
*************************************************/

	m_targetFile.WriteString("/**************************点阵数组********************/");
	m_targetFile.WriteString("\ncode char chineseFontOrg[] =\n{\n");


	unsigned char dianzhen[288];
	unsigned char hch,lch;
	unsigned int offse = 0;
	CFile hzkLib;
	CString m_path;
    m_path = m_hzLibDir + m_fontSel + m_dianzhenSel;
    unsigned short byteNum;

	hzkLib.Open(m_path, CFile::modeRead);

	if(m_dianzhenSel == "12")
	{
//		m_byteNum = 32;
//		m_rows = 16;
//		byteNum = 24;
		if(m_fontSel == "ASC")
		{
			byteNum = m_byteNum = 12;
		}
		else
		{
			byteNum = m_byteNum = 24;
		}
		m_rows = 12;
	}
	else if(m_dianzhenSel == "16")
	{
		byteNum = m_byteNum = 32;
		m_rows = 16;
	}
	else if(m_dianzhenSel == "24")
	{
		byteNum = m_byteNum = 72;
		m_rows = 24;
	}
	else if(m_dianzhenSel == "40")
	{
		byteNum = m_byteNum = 200;
		m_rows = 40;
	}
	else if(m_dianzhenSel == "48")
	{
		byteNum = m_byteNum = 288;
		m_rows = 48;
	}

    m_position = 0;
	m_tempFile.SeekToBegin();
	for(i=0; i<m_hzNum; i++)
	{
		hch = (unsigned char)(hzint[i]>>8) + 95;
		lch = (unsigned char)hzint[i] + 95;
		offse = (long)((lch)*94+(hch))*byteNum;
		hzkLib.Seek(offse,SEEK_SET);
		hzkLib.Read(dianzhen, byteNum);
		m_targetFile.WriteString("//  ");
		m_targetFile.Write(&hzint[i], 2);
        str.Format("\t\t\t机内码:\t0x%04x \t\t\t\n", hzint[i]);
		m_targetFile.WriteString(str);
/*
		if(byteNum == 24)
		{
			for(j=0;j<12;j++)
			{
				dianzhen12[j] = (short)dianzhen[j*2] * 256 + dianzhen[j*2+1];
			}
			for(j=0;j<4;j++)
			{
				dianzhen[j] = 0;
			}
			for(j=0;j<12;j++)
			{
				dianzhen12[j] >>= 2;
				dianzhen[j*2+4] = (unsigned char)(dianzhen12[j] >> 8);
				dianzhen[j*2+5] = (unsigned char)dianzhen12[j];
			}
			for(j=28;j<32;j++)
			{
				dianzhen[j] = 0;
			}
		}
*/
		for(j=0;j<m_byteNum;j++)
		{
			if(i==m_hzNum-1 && j==m_byteNum-1)
			{
				str.Format("0x%02X",dianzhen[j]);
			}
			else
			{
				str.Format("0x%02X,",dianzhen[j]);
			}
			m_targetFile.WriteString(str);
			if(((j+1)%16 == 0) || j==m_byteNum-1)
			{
				m_targetFile.WriteString("\n");
			}
		}
		m_tempFile.Write(dianzhen, m_byteNum);
	}

⌨️ 快捷键说明

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