如何控制编辑框输入数据的位数的啊?比如要输入的必须是5位,应该怎么办的?
还有啊,就是必须输入的数据形式是***.**应该怎么处理的?
就是如果输入是3,我要使它变成003.00的形式,或则此时我出现一个提示框说明数据的输入格式,
我希望是可以后台改变成003.00!应该怎么弄啊?

解决方案 »

  1.   

    自己重载CEdit类,首先处理键盘输入(允许数字和.

    其次,在其失去焦点的时候,进行数据整理,转换一下格式就可以
      

  2.   

    从 CEdit 派生一个类出来, 在重载输入变化消息处理函数, 在里面检查输入的位数,
      

  3.   

    if(WM_CHAR == pMsg->message)
    {
    if(GetDlgItem(IDC_CHAR)->GetSafeHwnd() == pMsg->hwnd)
    {
    bool bDo = true;//是否作处理 //允许用户输入两种删除键,故不处理
    const unsigned int chCharCode =  pMsg->wParam;  
    if(chCharCode == VK_DELETE || chCharCode == VK_BACK)
    bDo = false;

    //如果选中全部,可以任意输入
    int nStart,nEnd;
    ((CEdit*)GetDlgItem(IDC_CHAR))->GetSel(nStart,nEnd);
    if(0 == nStart && nEnd == m_char.GetLength())
    bDo = false ; //长度小于1可以处理
    int len = MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,m_char,-1,NULL,0);
    if(len-1 < 1)//len -1 才是长度
    bDo = false ;

    if(bDo)
    return true;
    }
    else if(GetDlgItem(IDC_ASCLL16)->GetSafeHwnd() == pMsg->hwnd)
    {
    bool bDo = true;//是否作处理

    //允许用户输入两种删除键,故不处理
    const unsigned int chCharCode =  pMsg->wParam;  
    if(chCharCode == VK_DELETE || chCharCode == VK_BACK)
    bDo = false;

    //如果选中全部,可以任意输入
    int nStart,nEnd;
    ((CEdit*)GetDlgItem(IDC_ASCLL16))->GetSel(nStart,nEnd);
    CString strText ;
    GetDlgItem(IDC_ASCLL16)->GetWindowText(strText);
    if(0 == nStart && nEnd == strText.GetLength())
    bDo = false ;

    //长度小于4可以处理
    if(strText.GetLength() < 4)//len -1 才是长度
    if((chCharCode >='0' && chCharCode <='9') //0-9允许输入
     ||(chCharCode >='A' && chCharCode <='F') //A到F可以输入
     ||(chCharCode >='a' && chCharCode <='f'))//a到f可以输入
     bDo = false;

    if(bDo)
    return true;
    }

    }