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

📄 numberdlg.cpp

📁 把阿拉伯数字转化为中文数字的软件
💻 CPP
字号:
// NUMBERDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NUMBER.h"
#include "NUMBERDlg.h"
#include "LGNumber.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()

/////////////////////////////////////////////////////////////////////////////
// CNUMBERDlg dialog

CNUMBERDlg::CNUMBERDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNUMBERDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNUMBERDlg)
	m_1 = _T("");
	m_2 = _T("");
	m_3 = _T("");
	m_4 = _T("");
	m_5 = _T("");
	m_6 = _T("");
	m_7 = _T("");
	m_8 = _T("");
	m_9 = _T("");
	m_10 = _T("");
	m_11 = _T("");
	m_c = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CNUMBERDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNUMBERDlg)
	DDX_Text(pDX, IDC_EDIT1, m_1);
	DDX_Text(pDX, IDC_EDIT2, m_2);
	DDX_Text(pDX, IDC_EDIT3, m_3);
	DDX_Text(pDX, IDC_EDIT4, m_4);
	DDX_Text(pDX, IDC_EDIT5, m_5);
	DDX_Text(pDX, IDC_EDIT6, m_6);
	DDX_Text(pDX, IDC_EDIT7, m_7);
	DDX_Text(pDX, IDC_EDIT8, m_8);
	DDX_Text(pDX, IDC_EDIT9, m_9);
	DDX_Text(pDX, IDC_EDIT10, m_10);
	DDX_Text(pDX, IDC_EDIT11, m_11);
	DDX_Check(pDX, IDC_CHECK1, m_c);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNUMBERDlg, CDialog)
	//{{AFX_MSG_MAP(CNUMBERDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNUMBERDlg message handlers

BOOL CNUMBERDlg::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
	numNum="0123456789.";
	numChina="零壹贰叁肆伍陆柒捌玖点";
	numChinaWeigh="个拾佰仟万拾佰仟亿拾佰仟万拾佰仟亿";

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

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

void CNUMBERDlg::OnChangeEdit1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	UpdateData(true);
	
	//if (m_1.Mid(0,2).Compare("零")==0&&m_8.Mid(2,2).Compare("个")!=0)
	//	m_8.Delete(0,2);

	CString m_1a=m_1;
	m_1a.Format("%.2f",atof(m_1a));
	m_2=m_1a;
	m_3=m_4="";
	//m_2:1234->壹贰叁肆
	for(int i=0;i<11;i++)
	{
		m_2.Replace(numNum.Mid(i,1),numChina.Mid(i*2,2));
	}

	//m_3:佰拾万仟佰拾个
	int iLen =m_1a.GetLength();
	if (iLen>16)
	{
		m_2=m_3=m_4=m_5=m_6=m_7=m_8=m_9="越界错!";
		goto call;
	}
	if (m_1a.Find('.')>0)
		iLen=m_1a.Find('.');

	for(i=iLen;i>=1;i--)
	{
		m_3+=numChinaWeigh.Mid((i-1)*2,2);
	}
	//m_4:2行+3行

	for(i=0;i<m_3.GetLength();i+=2)
	{
		m_4+=m_2.Mid(i,2)+m_3.Mid(i,2);
	}
	//m_5:4行去"0"后拾佰仟

	m_5=m_4;
	m_5.Replace("零拾","零");
	m_5.Replace("零佰","零");
	m_5.Replace("零仟","零");
	
	//m_6:00->0,000->0

	m_6=m_5;
	for(;m_6.Replace("零零","零"););
	//等同while(m_6.Replace("零零","零"));


	//m_7:6行去亿,万,个位"0"
	m_7=m_6;
	m_7.Replace("亿零万零","亿零");
	m_7.Replace("亿零万","亿零");
	m_7.Replace("零亿","亿");
	m_7.Replace("零万","万");
	if (m_7.GetLength()>4)
		m_7.Replace("零个","个");
	//m_8:7行+2行小数->数目

	m_8=m_7;
	m_8.Replace("个","");
	if(m_2.Right(6).Compare("点零零")!=0)
		m_8+=m_2.Right(6);
	m_8.Replace("亿万","亿");
	//m_9:7行+2行小数->价格
	m_9=m_7;
	m_9.Replace("个","圆");
	if(m_2.Right(6).Compare("点零零")!=0)
	{
		m_9+=m_2.Right(4);
		m_9.Insert(m_9.GetLength()-2,"角");
		m_9+="分";
	}
	else m_9+="整 ";
	m_9.Replace("亿万","亿");
	if(m_9!="零圆整")
		m_9.Replace("零圆","");
	m_9.Replace("零分","整");



	

call:	LGNumber Number;
	m_10=Number.fToChineseText(m_1a);
	m_11=Number.fToChinesePrice(m_1a);
	UpdateData(false);



	// 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
	
}

HBRUSH CNUMBERDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	if (((CStatic*)GetDlgItem(IDC_STATIC1))->m_hWnd==pWnd->m_hWnd&&m_c==1)
		pDC->SetTextColor(RGB(255,0,0));
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CNUMBERDlg::OnCheck1() 
{
	// TODO: Add your control notification handler code here
	m_c=!m_c;
	((CStatic*)GetDlgItem(IDC_STATIC1))->Invalidate();
	CEdit *a=(CEdit *)GetDlgItem(IDC_EDIT1);
	if (m_c)
	a->SetReadOnly();
	else
		a->SetReadOnly(false);

}

⌨️ 快捷键说明

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