Wednesday, June 20, 2007

How to add text in CEditView

1. CEdit::ReplaceSel

ReplaceSel replaces only a portion of the text in an edit control.
To access CEdit control, use GetEditCtrl() function.

GetEditCtrl().SetSel(-1, -1); // end of edit text
GetEditCtrl().ReplaceSel(buf); // append string..
GetEditCtrl().SendMessage(EM_SCROLLCARET); // ..and show caret

2. CWnd::SetWindowText

SetWindowText will replace all of the text, therefore first is required get all widows text into local variable, append text to the end and show on screen by using SetWindowText

CString str;
GetWindowText(str);
str += " appended string ";
SetWindowText(str);

No comments: