CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2010
    Posts
    33

    Edit box unlimited

    Hi all, I'm using a edit box as an "append log" for my program.

    I set it to "multiline" so I can write a new log every time. To write the log I append text using this code

    Code:
    CString strLine;
       // Add CR/LF to text
       strLine.Format(_T("\r\n%s"), pszText);
       // Get the initial text length
       int nLength = m_logedit.GetWindowTextLength();
       // Put the selection at the end of text
       m_logedit.SetSel(nLength, nLength);
       // Replace the selection
       m_logedit.ReplaceSel(strLine);

    The problem is that the edit box is keeping about 3-4000 lines. After that the edit box won't log more text and keeps itself stucked in adding more text.

    I thought two solutions:

    1) Increasing its size to unlimited or something
    2) Deleting previous text (like a ms-dos prompt does)


    Can you help me in the simpliest way you can please?

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Edit box unlimited

    The simples way is option 1 using SetTextLimit. The nicest way is option 2 because it eliminates the entire problem.

  3. #3
    Join Date
    May 2010
    Posts
    33

    Re: Edit box unlimited

    What about solution number two?

    How do I make "runtime deleting previous contents" ?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Edit box unlimited

    You can also wire up a CString variable using the DDX mechanism and let MFC handle the data transfer for you.

    Another approach is to use a List Control set to report mode. That way you can append a new line without having to overright the previous text. If you were really clever, you could make the List Control virtual and bind to a collection.

  5. #5
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Edit box unlimited

    Quote Originally Posted by pm44xl22 View Post
    What about solution number two?

    How do I make "runtime deleting previous contents" ?
    Simply use SetSel and ReplaceSel to delete a part of text at the beginning of your editbox.

  6. #6
    Join Date
    May 2010
    Posts
    33

    Re: Edit box unlimited

    Do you find that it may be useful sublassing the control?

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Edit box unlimited

    You could also use a ListBox like A Logging ListBox Control
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured