在EDIT BOX中有一个字符串Q2345ETEWE%%R,如何使光标定位在任意字符比如3后面,使得程序一执行,不用单击鼠标,即可在3后插入字符?

解决方案 »

  1.   

    CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
    pEdit->SetFocus();
    pEdit->SetSel(3, 3, FALSE);
      

  2.   

    Sorry,看作题了,改正:
    CString strInsert = "!!!"; CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
    int nStart, nEnd;
    pEdit->GetSel(nStart, nEnd);
    CString strEdit, strLeft, strRight;
    pEdit->GetWindowText(strEdit);
    strLeft = strEdit.Left(nStart);
    strRight = strEdit.Right(strEdit.GetLength()-nEnd);
    strEdit = strLeft+ strInsert + strRight;
    pEdit->SetWindowText(strEdit);
    pEdit->SetFocus();
    pEdit->SetSel(strLeft.GetLength(), strLeft.GetLength()+strInsert.GetLength(), FALSE);