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;
}

参考:

Microsoft CEditView类说明文档

Microsoft CEdit类说明文档