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

📄 hanzidlg.cpp

📁 用8052写的一个LED大屏幕显示程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// hanziDlg.cpp : implementation file
//

#include "stdafx.h"
#include "hanzi.h"
#include "hanziDlg.h"
#include "afx.h"
#include "iostream.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()

/////////////////////////////////////////////////////////////////////////////
// CHanziDlg dialog

CHanziDlg::CHanziDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CHanziDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CHanziDlg)
	m_quma = 1;
	m_weima = 1;
	m_writeplace = -1;
	m_WordType = -1;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CHanziDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHanziDlg)
	DDX_Control(pDX, IDC_COMBO1, m_ctlCombo1);
	DDX_Control(pDX, IDC_COMBO2, m_ctlCombo2);
	DDX_Control(pDX, IDC_LIST1, m_listctrl);
	DDX_Control(pDX, IDC_SPIN2, m_spin2);
	DDX_Control(pDX, IDC_SPIN1, m_spin1);
	DDX_Text(pDX, IDC_EDIT1, m_quma);
	DDX_Text(pDX, IDC_EDIT2, m_weima);
	DDX_CBIndex(pDX, IDC_COMBO1, m_writeplace);
	DDX_CBIndex(pDX, IDC_COMBO2, m_WordType);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CHanziDlg, CDialog)
	//{{AFX_MSG_MAP(CHanziDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDD_FILE_OPEN, OnFileOpen)
	ON_BN_CLICKED(IDD_SHOWCHINESE, OnShowchinese)
	ON_BN_CLICKED(IDD_SOURCEFILE, OnSourcefile)
	ON_BN_CLICKED(IDD_OBJECTFILE, OnObjectfile)
	ON_BN_CLICKED(IDC_BEGINWRITE, OnBeginwrite)
	ON_BN_CLICKED(IDD_SOURCEFILE_C, OnSourcefileC)
	ON_BN_CLICKED(IDD_OBJECTFILE_C, OnObjectfileC)
	ON_BN_CLICKED(IDC_BEGINWRITE_C, OnBeginwriteC)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHanziDlg message handlers

BOOL CHanziDlg::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

	//字模的显示
	m_listctrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);

	m_listctrl.InsertColumn(0,"1",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(1,"2",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(2,"3",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(3,"4",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(4,"5",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(5,"6",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(6,"7",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(7,"8",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(8,"9",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(9,"0",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(10,"1",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(11,"2",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(12,"3",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(13,"4",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(14,"5",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(15,"6",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(16,"7",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(17,"8",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(18,"9",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(19,"0",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(20,"1",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(21,"2",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(22,"3",LVCFMT_CENTER,14);
	m_listctrl.InsertColumn(23,"4",LVCFMT_CENTER,14);

	m_ctlCombo1.SetCurSel(1);
	m_ctlCombo2.SetCurSel(0);

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

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

///////////////////////////////////////////////////////////////////////
// open file and read
///////////////////////////////////////////////////////////////////////
void CHanziDlg::OnFileOpen() 
{
	// TODO: Add your control notification handler code here
	static char BASED_CODE szFilter[] = "字库文件 (*.bin *.hzk)|*.bin;*.hzk|所有文件 (*.*)|*.*||";
	CFileDialog dlg(TRUE, NULL,  NULL,  OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,  szFilter,  NULL);
	if(dlg.DoModal() == IDCANCEL)
		return;
	
	m_FileName = dlg.GetPathName();

}


///////////////////////////////////////////////////////////////////////////
//show chinese model
///////////////////////////////////////////////////////////////////////////
void CHanziDlg::OnShowchinese() 
{
	CFile f;
	if(!f.Open(m_FileName,CFile::modeRead,NULL))
	{
		CString str;
		str.Format("打开%s字库文件时出错!",m_FileName);
		//str = "请正确选择字库文件!";
		AfxMessageBox(str);
		return;
	}
	f.SeekToBegin();

////////////////////////////////////////////////////////////////////////////
	m_listctrl.DeleteAllItems();                //清空字模显示控件
	//m_listctrlshowall.DeleteAllItems();         //清空汉字列表控件
	UpdateData(TRUE);

	if(m_WordType == -1)       // 提示选择字模点阵
	{
		AfxMessageBox("请选择字模点阵");
		return;
	}

	if(m_WordType == 0)       // 显示16点阵字模
	{
		int		 a,b,c,i,j,k;
		BYTE	 n,buffer[32] = "";      //设定一个(16点阵)字模的缓冲区
		CString  m[16];
		DWORD    dwRead;
		a = m_quma;
		b = m_weima;
		if(a == 0 || b == 0 || a > 94 || b > 94)
		{
			AfxMessageBox("区码、位码不能等于0或大于94");
			return;
		}
		c = 32 * (94 * (a - 1) + b - 1);
		f.Seek(c,CFile::begin);
		dwRead = f.Read(buffer,32);
		for(i = 0 ; i < 16 ; i++)
		{
			for(k = 0 ; k < 2 ; k++)
			{
				for(j = 0 ; j < 8 ; j++)
				{
					n = buffer[2 * i + k] >> j;
					n = n & 0x01;
					if(n == 0x01)
						m[8*k + j] = "■";
					else
						m[8*k + j] = "  ";
				}
			}
		
			int m_nItemCount = m_listctrl.GetItemCount();

			m_listctrl.InsertItem(m_nItemCount,m[7]);
			m_listctrl.SetItemText(m_nItemCount,1,m[6]);
			m_listctrl.SetItemText(m_nItemCount,2,m[5]);
			m_listctrl.SetItemText(m_nItemCount,3,m[4]);
			m_listctrl.SetItemText(m_nItemCount,4,m[3]);
			m_listctrl.SetItemText(m_nItemCount,5,m[2]);
			m_listctrl.SetItemText(m_nItemCount,6,m[1]);
			m_listctrl.SetItemText(m_nItemCount,7,m[0]);
			m_listctrl.SetItemText(m_nItemCount,8,m[15]);
			m_listctrl.SetItemText(m_nItemCount,9,m[14]);
			m_listctrl.SetItemText(m_nItemCount,10,m[13]);
			m_listctrl.SetItemText(m_nItemCount,11,m[12]);
			m_listctrl.SetItemText(m_nItemCount,12,m[11]);
			m_listctrl.SetItemText(m_nItemCount,13,m[10]);
			m_listctrl.SetItemText(m_nItemCount,14,m[9]);
			m_listctrl.SetItemText(m_nItemCount,15,m[8]);
			m_listctrl.SetItemText(m_nItemCount,16,"┃");
		
		}
			int m_nItemCount = m_listctrl.GetItemCount();
			m_listctrl.InsertItem(m_nItemCount,"━");
			m_listctrl.SetItemText(m_nItemCount,1,"━");
			m_listctrl.SetItemText(m_nItemCount,2,"━");
			m_listctrl.SetItemText(m_nItemCount,3,"━");

⌨️ 快捷键说明

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