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

📄 hanzidlg.cpp

📁 at指令
💻 CPP
字号:
// hanziDlg.cpp : implementation file
//

#include "stdafx.h"
#include "hanzi.h"
#include "hanziDlg.h"
#include"pinyin.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_strValue ="00H,04H,2FH,7EH,F9H,04H,A9H,04H, AAH,14H,AAH,7CH,ACH,54H,AAH,54H, AAH,54H,A9H,54H,E9H,74H,ADH,54H, 0AH,04H,08H,04H,08H,14H,08H,0CH,";
	m_bgrid = FALSE;
	m_strHanzi = _T("");
	m_strPinyin = _T("");
	m_vh = 0;
	//}}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_PIC, m_ctrlpic);
	DDX_Text(pDX, IDC_EDTV, m_strValue);
	DDX_Check(pDX, IDC_GRID, m_bgrid);
	DDX_Text(pDX, IDC_HANZI, m_strHanzi);
	DDX_Text(pDX, IDC_PINYIN, m_strPinyin);
	DDX_Radio(pDX, IDC_RADIO1, m_vh);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CHanziDlg, CDialog)
	//{{AFX_MSG_MAP(CHanziDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_GO, OnGo)
	ON_BN_CLICKED(IDC_GRID, OnGrid)
	ON_NOTIFY(UDN_DELTAPOS, IDC_FANG, OnDeltaposFang)
	ON_EN_SETFOCUS(IDC_EDTV, OnSetfocusEdtv)
	ON_EN_KILLFOCUS(IDC_HANZI, OnKillfocusHanzi)
	ON_EN_CHANGE(IDC_PINYIN, OnChangePinyin)
	ON_EN_KILLFOCUS(IDC_PINYIN, OnKillfocusPinyin)
	ON_WM_CLOSE()
	ON_WM_KEYDOWN()
	ON_WM_CHAR()
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_EN_SETFOCUS(IDC_PINYIN, OnSetfocusPinyin)
	ON_EN_CHANGE(IDC_HANZI, OnChangeHanzi)
	ON_EN_SETFOCUS(IDC_HANZI, OnSetfocusHanzi)
	ON_COMMAND(IDM_CONFIG, OnConfig)
	ON_COMMAND(IDM_EXIT, OnExit)
	ON_COMMAND(IDM_USEHELP, OnUsehelp)
	ON_COMMAND(IDM_ABOUT, OnAbout)
	//}}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_ctrlpic.SetBak(RGB(0,0,0));
	m_ctrlpic.SetFore(RGB(255,255,255));
    m_selwin.Create(CSelWin::IDD,this);
    //m_selwin.DoModal();
	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;
}

void CHanziDlg::OnGo() 
{
	// TODO: Add your control notification handler code here
    
    
	UpdateData();
     CGridPic* psta=(CGridPic*)GetDlgItem(IDC_PIC);
	psta->FillMask(m_strValue);
	psta->Invalidate();
	
} 

//DEL void CHanziDlg::ClrBuffer()
//DEL {
//DEL   unsigned char * pbuf=m_hanzi;
//DEL 	for(int i=0;i<16*2;i++)
//DEL 	{
//DEL 		*pbuf=0;
//DEL 		pbuf++;
//DEL 	}
//DEL }



void CHanziDlg::OnGrid() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CGridPic* psta=(CGridPic*)GetDlgItem(IDC_PIC);
	psta->SetGrid(m_bgrid);
	psta->Invalidate();
}

//DEL void CHanziDlg::OnRadio7() 
//DEL {
//DEL 	// TODO: Add your control notification handler code here
//DEL     UpdateData();
//DEL 	CGridPic* psta=(CGridPic*)GetDlgItem(IDC_PIC);
//DEL 	psta->SetAlign(m_vh);
//DEL 	 int i;
//DEL    unsigned char * pmask=psta->GetMask();
//DEL    char buf[10];
//DEL    unsigned char bv;
//DEL    CString stemp,strValue;
//DEL    for(i=1;i<=32;i++)
//DEL    {
//DEL 	  bv=pmask[i-1];
//DEL 	  itoa(bv,buf,16);
//DEL 	  if(bv<0x10)
//DEL 	    stemp.Format("0%sH,",buf);
//DEL 	  else
//DEL         stemp.Format("%sH,",buf);
//DEL 	  if(!(i%8))
//DEL 		  stemp+="\r\x0a";
//DEL 	  stemp.MakeUpper();
//DEL 	  strValue+=stemp;
//DEL    }
//DEL    m_strValue=strValue;
//DEL    UpdateData(FALSE);
//DEL 	
//DEL }

//DEL void CHanziDlg::OnRadio8() 
//DEL {
//DEL 	// TODO: Add your control notification handler code here
//DEL 	UpdateData();
//DEL 	CGridPic* psta=(CGridPic*)GetDlgItem(IDC_PIC);
//DEL 	psta->SetAlign(m_vh);
//DEL 		 int i;
//DEL    unsigned char * pmask=psta->GetMask();
//DEL    char buf[10];
//DEL    unsigned char bv;
//DEL    CString stemp,strValue;
//DEL    for(i=1;i<=32;i++)
//DEL    {
//DEL 	  bv=pmask[i-1];
//DEL 	  itoa(bv,buf,16);
//DEL 	  if(bv<0x10)
//DEL 	    stemp.Format("0%sH,",buf);
//DEL 	  else
//DEL         stemp.Format("%sH,",buf);
//DEL 	  if(!(i%8))
//DEL 		  stemp+="\r\x0a";
//DEL 	  stemp.MakeUpper();
//DEL 	  strValue+=stemp;
//DEL    }
//DEL    m_strValue=strValue;
//DEL    UpdateData(FALSE);
//DEL 	//psta->Invalidate();
//DEL }

void CHanziDlg::OnDeltaposFang(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
	int i=pNMUpDown->iDelta;
	UpdateData();
	CGridPic* psta=(CGridPic*)GetDlgItem(IDC_PIC);
	if(i<0)
		psta->DeltaRect(TRUE);
	else
		psta->DeltaRect(FALSE);
	
	
	psta->Invalidate();
	*pResult = 0;
}

void CHanziDlg::OnSetfocusEdtv() 
{
	// TODO: Add your control notification handler code here
    //m_strValue.Empty();
	//UpdateData(FALSE);
}

void CHanziDlg::OnKillfocusHanzi() 
{
	// TODO: Add your control notification handler code here
   

}

void CHanziDlg::OnChangePinyin() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData();
	if(m_strPinyin.IsEmpty())
		return;
	m_strPinyin.MakeLower();
	m_strPinyin.TrimLeft();
	m_strPinyin.TrimRight();
	unsigned char** pbuff=0;
    pbuff=py_ime((unsigned char*)m_strPinyin.GetBuffer(0));
	CRect rt;
	CEdit* pedt=(CEdit*)GetDlgItem(IDC_PINYIN);
	pedt->GetWindowRect(&rt);
	m_selwin.SetTextv(CString(pbuff[0]));
	m_selwin.SetWindowPos(NULL,rt.left,rt.bottom+20,0,0,SWP_NOSIZE|SWP_SHOWWINDOW);
    //m_selwin.ShowWindow(SW_SHOW);
    pedt->SetFocus();

}

void CHanziDlg::OnKillfocusPinyin() 
{
	// TODO: Add your control notification handler code here
  


}

void CHanziDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	m_selwin.DestroyWindow();
	CDialog::OnClose();
}

void CHanziDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CHanziDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default

	switch(nChar)
	{
	case VK_DOWN:
        m_selwin.NextPage();
		break;
	}

	CDialog::OnChar(nChar, nRepCnt, nFlags);
}

LRESULT CHanziDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CDialog::WindowProc(message, wParam, lParam);
}

BOOL CHanziDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->hwnd==GetDlgItem(IDC_EDTV)->GetSafeHwnd())
		return CDialog::PreTranslateMessage(pMsg);
	if(pMsg->message==WM_KEYDOWN)
	{
	  int nChar=(int)pMsg->wParam;
	  CEdit* pedt=(CEdit*)GetDlgItem(IDC_PINYIN);
	  
	if(nChar==VK_RETURN||(nChar>=0x30&&nChar<=0x39))
	{
		int iv=nChar-0x30;
		if(nChar==VK_RETURN)
			iv=0;
		if(iv>(m_selwin.m_chtcnts-1))return true;
		CEdit* psta=(CEdit*)GetDlgItem(IDC_HANZI);
		m_strHanzi=m_selwin.m_strBak.Mid(m_selwin.m_curpage*20+iv*2,2);
		m_strPinyin.Empty();
	    UpdateData(false);
		OnChangeHanzi();
		return true;
		
    }
	if(nChar==VK_ESCAPE)
	{
        m_selwin.ShowWindow(SW_HIDE);
		return true;
	}
	switch(nChar)
	{
	case VK_DOWN:
        m_selwin.NextPage();
		break;
	case VK_UP:
		m_selwin.PrevPage();
		break;
	}

	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CHanziDlg::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CGridPic* psta=(CGridPic*)GetDlgItem(IDC_PIC);
	psta->SetAlign(m_vh);
	 int i;
   unsigned char * pmask=psta->GetMask();
   char buf[10];
   unsigned char bv;
   CString stemp,strValue;
   for(i=1;i<=32;i++)
   {
	  bv=pmask[i-1];
	  itoa(bv,buf,16);
	  if(bv<0x10)
	    stemp.Format("0%sH,",buf);
	  else
        stemp.Format("%sH,",buf);
	  if(!(i%8))
		  stemp+="\r\x0a";
	  stemp.MakeUpper();
	  strValue+=stemp;
   }
   m_strValue=strValue;
   UpdateData(FALSE);
}

void CHanziDlg::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CGridPic* psta=(CGridPic*)GetDlgItem(IDC_PIC);
	psta->SetAlign(m_vh);
	 int i;
   unsigned char * pmask=psta->GetMask();
   char buf[10];
   unsigned char bv;
   CString stemp,strValue;
   for(i=1;i<=32;i++)
   {
	  bv=pmask[i-1];
	  itoa(bv,buf,16);
	  if(bv<0x10)
	    stemp.Format("0%sH,",buf);
	  else
        stemp.Format("%sH,",buf);
	  if(!(i%8))
		  stemp+="\r\x0a";
	  stemp.MakeUpper();
	  strValue+=stemp;
   }
   m_strValue=strValue;
   UpdateData(FALSE);
}

void CHanziDlg::OnSetfocusPinyin() 
{
	// TODO: Add your control notification handler code here
	m_vh=0;
}

void CHanziDlg::OnChangeHanzi() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData();
	if(m_strHanzi.GetLength()<2)
		return;
  
   UpdateData();
   if(m_strHanzi.IsEmpty())
	   return;
   CGridPic* psta=(CGridPic*)GetDlgItem(IDC_PIC);
   psta->m_align=0;
   unsigned char bv,bv1;
   DWORD offset;
   CString strValue("");
   bv=m_strHanzi[0];
   bv1=m_strHanzi[1];
   CFile fhz;
   if(!fhz.Open("hzk16",CFile::modeRead))
   {
	   MessageBox("File open failed");
	   return ;
   }
   offset=((bv-161)*94+(bv1-161))*32;
   fhz.Seek(offset,CFile::begin);
   int i;
   unsigned char * pmask=psta->GetMask();
   char buf[10];
   CString stemp;
   for(i=1;i<=32;i++)
   {
      fhz.Read(&bv,sizeof(bv));
	  *(pmask+i-1)=bv;
	  itoa(bv,buf,16);
	  if(bv<0x10)
	    stemp.Format("0%sH,",buf);
	  else
        stemp.Format("%sH,",buf);
	  if(!(i%8))
		  stemp+="\r\x0a";
	  stemp.MakeUpper();
	  strValue+=stemp;
   }
   m_strValue=strValue;
   UpdateData(false);
   fhz.Close();
	
}

void CHanziDlg::OnSetfocusHanzi() 
{
	// TODO: Add your control notification handler code here
   	
}

void CHanziDlg::OnConfig() 
{
	// TODO: Add your command handler code here
	
}

void CHanziDlg::OnExit() 
{
	// TODO: Add your command handler code here
	PostMessage(WM_CLOSE,0,0);
}

void CHanziDlg::OnUsehelp() 
{
	// TODO: Add your command handler code here
	
}

void CHanziDlg::OnAbout() 
{
	// TODO: Add your command handler code here
	CAboutDlg dlgAbout;
	dlgAbout.DoModal();
}

//DEL void CHanziDlg::OnBexit() 
//DEL {
//DEL 	// TODO: Add your command handler code here
//DEL 	
//DEL }

⌨️ 快捷键说明

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