CEditView末尾增加文本
CEditView中使用CEdit作为编辑控件,所以可以通过CEdit的方法来改变CEditView中的文字。
取得CEdit的方法:

GetEditCtrl的说明:
CEditView:: GetEditCtrl
调用GetEditCtrl以获取对 “编辑” 视图使用的编辑控件的引用。1
CEdit& GetEditCtrl() const;
返回值
对CEdit对象的引用。
备注
此控件的类型为CEdit, 因此可以使用CEdit成员函数直接操作 Windows 编辑控件。
实现代码如下:1
2
3
4
5
6
7
8
9
10
11
12//  class CXXXView : public CEditView
int CXXXView::AddString(const CString & string)
{
    // CEditView::GetEditCtrl 提供对CEdit CEditView对象 (Windows 编辑控件) 的部分的访问。
    CEdit& thisEdit = GetEditCtrl();
    int nLength = thisEdit.GetWindowTextLength();
    // 选定当前文本的末端
    thisEdit.SetSel(nLength, nLength);
    // 追加文本
    thisEdit.ReplaceSel(string);
    return 0;
}
参考:
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 张拓的博客!





