MFC, append text to textbox

/ Published in: C++
Save to your folder(s)

Set textbox to multi-line. ASSERT statement verifies.

Apparently executes quicker than GetWindowText, Append, SetWindowText.

Appears to auto-scroll otherwise, use this to scroll to bottom:
edit.SendMessage(WM_VSCROLL, SB_BOTTOM, 0 );

Haven't figured out how to stop scrolling when it's not already at the bottom.

Copy this code and paste it in your HTML
  1. void AppendLineToMultilineEditCtrl(CEdit& editArg, LPCTSTR pszTextArg )
  2. {
  3. ASSERT( editArg.GetStyle() & ES_MULTILINE ); // Should be a multi-line style. 0x0004L
  4. int nLength = editArg.GetWindowTextLength(); // get the initial text length
  5. editArg.SetSel(nLength, nLength); // go to the end.
  6. editArg.ReplaceSel("
  7. "); // add CrLf
  8. nLength+=2; // Add length of CrLf
  9. editArg.SetSel(nLength, nLength); // go after CrLf.
  10. editArg.ReplaceSel(pszTextArg); // add the string.
  11. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.