Return to Snippet

Revision: 21712
at December 18, 2009 18:35 by jimfred


Updated Code
void AppendLineToMultilineEditCtrl(CEdit& editArg, LPCTSTR pszTextArg )
{
   ASSERT(  editArg.GetStyle() & ES_MULTILINE ); // Should be a multi-line style. 0x0004L
   int nLength = editArg.GetWindowTextLength(); // get the initial text length
   editArg.SetSel(nLength, nLength); // go to the end.
   editArg.ReplaceSel("
");       // add CrLf
   nLength+=2;                       // Add length of CrLf
   editArg.SetSel(nLength, nLength); // go after CrLf.
   editArg.ReplaceSel(pszTextArg);   // add the string.
}

Revision: 21711
at December 18, 2009 18:17 by jimfred


Initial Code
void AppendLineToMultilineEditCtrl(CEdit& editArg, LPCTSTR pszTextArg )
{
   int nLength = editArg.GetWindowTextLength(); // get the initial text length
   editArg.SetSel(nLength, nLength); // put the selection at the end of text
   editArg.ReplaceSel("
"); // replace the selection
   nLength+=2;
   editArg.SetSel(nLength, nLength); // put the selection at the end of text
   editArg.ReplaceSel(pszTextArg); // replace the selection
}

Initial URL


Initial Description
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.

Initial Title
MFC, append text to textbox

Initial Tags


Initial Language
C++