对话框里面有一个编辑框,我希望用户只能输入“中国人”这三个字符里面的任意一个字符,这样该怎么做?
请各位帮忙,我做了一天了也没做好,就要交差了!!!!

解决方案 »

  1.   

    改用组合框来让用户选这三个字,不让他有输入的机会.这种情况流行都是这么处理,用编辑框不能输入别的字,让人觉得你的程序有bug.不太好.
      

  2.   

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_editctls.asp?frame=true
      

  3.   

    试一下这个,以前帮别人做过的改动一下
    void CDlgTest5Dlg::OnChangeEdit1() 
    {
    // 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 static char *strA="中";
    static char *strB="国";
    static char *strC="人";
    BOOL bWrite=TRUE;
    char str2[3]={0,0,0};
    CString text;
    GetDlgItem(IDC_EDIT1)->GetWindowText(text);
    int iStart=HIWORD(((CEdit*)GetDlgItem(IDC_EDIT1))->GetSel());
    if(iStart>0)
    {
    if(iStart>1)
    {
    if(!((text[iStart-2]==strA[0]&&text[iStart-1]==strA[1])
    ||(text[iStart-2]==strB[0]&&text[iStart-1]==strB[1])
    ||(text[iStart-2]==strC[0]&&text[iStart-1]==strC[1])))
    {
    bWrite=FALSE;
    }
    }else
    bWrite=FALSE;

    if(!bWrite)
    {
    str2[0]=text[iStart-1];
    BOOL bDB=FALSE;
    if(text[iStart-1]<0)
    {
    str2[1]=str2[0];
    str2[0]=text[iStart-2];
    bDB=TRUE;
    }
    text.Replace(str2,"");
    GetDlgItem(IDC_EDIT1)->SetWindowText(text);
    if(bDB)
    {
    ((CEdit*)GetDlgItem(IDC_EDIT1))->SetSel(iStart-2,iStart-2,-1);
    }else
    {
    ((CEdit*)GetDlgItem(IDC_EDIT1))->SetSel(iStart-1,iStart-1,-1);
    }
    }

    }
    }
      

  4.   

    感谢bluebohe(薄荷) (MVP)大侠,想不到第一次来论坛提问就这么快得到回复!
    好像这里要给分的,怎么结贴哦!