Posted By

jimfred on 12/18/09


Tagged

mfc


Versions (?)

MFC, append text to textbox


 / Published in: C++
 

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(WMVSCROLL, SBBOTTOM, 0 );

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

  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  

You need to login to post a comment.