November 21st, 2004, 07:39 AM
Edit Control: How to append text to an edit control?
Q: Which is the best method to append text to an edit control?
A: One method is to call 'GetWindowText()' to get the initial text, append the new text to it, then put it back with 'SetWindowText()'.
This works, but is not practical, especially if the text lenght is huge and the appending is made very frequently.
A better solution is to put the edit selection at the end of the initial text, then simply replace the selection with the text to append:
For appending lines in a multiline edit control we must add CR/LF to the text:
void CFoo::AppendTextToEditCtrl(CEdit& edit, LPCTSTR pszText)
// get the initial text length
int nLength = edit.GetWindowTextLength();
// put the selection at the end of text
// replace the selection
void CFoo::AppendLineToMultilineEditCtrl(CEdit& edit, LPCTSTR pszText)
// add CR/LF to text
Last edited by ovidiucucu; April 5th, 2006 at 09:11 AM.
Reason: "repair" a [color] tag
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.