如果只是追加数据而不是重设整个文本框的内容?

解决方案 »

  1.   

    CString str;
    GetDlgItem(IDC_EDIT1)->GetWindowText(str);
    str += "Add";
    GetDlgItem(IDC_EDIT1)->SetWindowText(str);
      

  2.   

    to he_zhidan:
    你就是重设了整个文本框的内容
      

  3.   

    to he_zhidan:
    你就是重设了整个文本框的内容====================
    ??????????????
      

  4.   

    我知道了,你要追加是吗?
    据我所知,普通edit好像没有功能。
      

  5.   

    就算你用第三方的CEdit类最后还是用的he_zhidan:的方法做的
      

  6.   

    下面的代码在文本框最后追加"abc"int nLength = m_edit.SendMessage(WM_GETTEXTLENGTH);
    m_edit.SetSel(nLength, nLength);
    m_edit.ReplaceSel("abc");
      

  7.   

    文本框中的字符串只有一个,不管怎么做,最终都是str+="AAA"的效果和效率
      

  8.   

    结果相同,效率不同void CEe1Dlg::OnButton1() 
    {
        int nStartTick, n;    m_edit.SetWindowText("");
        nStartTick = GetTickCount();
        for(n = 1; n < 500; n++)
        {
            int nLength = m_edit.SendMessage(WM_GETTEXTLENGTH);
            m_edit.SetSel(nLength, nLength);
            m_edit.ReplaceSel("abc");
        }
        afxDump << "ReplaceSel: " << GetTickCount() - nStartTick << "\n";}void CEe1Dlg::OnButton2() 
    {
        int nStartTick, n;    m_edit.SetWindowText("");
        nStartTick = GetTickCount();
        CString str;
        for(n = 1; n < 500; n++)
        {
            m_edit.GetWindowText(str);
            str += "abc";
            m_edit.SetWindowText(str);    }
        afxDump << "SetWindowText: " << GetTickCount() - nStartTick << "\n";
    }输出:
    ReplaceSel: 240
    SetWindowText: 2934
      

  9.   

    可能你的函数不用GetWindowText和SetWindowText而快的,还是CString Replace就要比+快呢?我明天试一下,你的做法不错
      

  10.   

    ReplaceSel: 1192
    SetWindowText: 41
    我测试的结果
      

  11.   

    我觉得bcpl(闲庭信步) 的方法比较快,你自己测一下拉