读书人

统制CEdit中文字输入格式(浮点类型)

发布时间: 2012-11-01 11:11:32 作者: rapoo

控制CEdit中文字输入格式(浮点类型)
void CExpendDlg::OnEnChangeEditExpendMoney()
{
// 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

CString strTemp;
CEdit* pEdit = (CEdit*) GetDlgItem(IDC_EDIT_EXPEND_MONEY);

pEdit->GetWindowText(strTemp);

int start = 0;
int end = 0;
pEdit->GetSel(start, end);

if (end == 0)
{
return;
}

if (strTemp.GetLength() > 0)
{
TCHAR character = strTemp.GetAt(end-1);

if ( ((!(character>='0' && character<='9') && character != '.'))
|| strTemp.Find('.') != strTemp.ReverseFind('.') )
{
int setPos = strTemp.GetLength();
strTemp.Delete(end-1, 1);
pEdit->SetWindowText(strTemp);
pEdit->SetSel(setPos-1,setPos-1);
}
}
}

读书人网 >编程

热点推荐