首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-11-01 
控制CEdit中文字输入格式(浮点类型)void CExpendDlg::OnEnChangeEditExpendMoney(){// TODO:If this is a

控制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);
        }
    }
}

热点排行