?
Solved

Carriage return in CRichEditCtrl

Posted on 1997-05-05
1
Medium Priority
?
781 Views
Last Modified: 2013-11-20
In MSVC 4.2, I have an multiline edit box of type CRichEditCtrl, and every line I insert goes to the first line. I tried to add EOL, \n, \r, \n\r, \r\n and nothing helps. Any hint?

        CRichEditCtrl   m_log;
        ...
        sprintf(log_msg, "Current script file: %s\r\n", scrname);
        m_log.SetWindowText(log_msg);

        sprintf(log_msg, "Current message file: %s\r\n", msgname);
        m_log.SetWindowText(log_msg);
0
Comment
Question by:aarone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
jmmougeolle earned 100 total points
ID: 1301325
That's normal you couldn't see more than one line with the code you give there!

First you have to know that calling SetWindowText will Replace ALL THE TEXT inside your CRichEditCtrl by the one you give there!

So if you do those 2 calls:
m_log.SetWindowText("First try");
//there you have the text "First try" in your CRichEdiCtrl
m_log.SetWindowText("Second try");
//there you have the text "Second try" in your CRichEdiCtrl
//what you have done there, is to replace "First try"
//by "Second Try"

In fact you got two ways to do what you wanna do!

1)  Use a Temporary Text to store all before putting it in the CRichEditCtrl


CRichEditCtrl m_log;
...
CString strWholeText;
sprintf(log_msg, "Current script file: %s\r\n", scrname);
strWholeText += log_msg;
sprintf(log_msg, "Current message file: %s\r\n", msgname);
strWholeText += log_msg;
m_log.SetWindowTextstrWholeText);


2) Add it by replacing the Selection, line after line

void AddLine(CString strLine)
{
//First retrieve the Whole Text selection value

//Remind Old Selection to put it back later
CHARRANGE oldCharRange;
m_log.GetSel(oldCharRange);
//Select All then
m_log.SetSel(0,-1);
long nUnusedStart, nUsefullEnd;
m_log.GetSel(nUnusedStart, nUsefullEnd);
//Select empty selection at end
m_log.SetSel(nUsefullEnd, nUsefullEnd);
//ReplaceSelection by the wanted line
m_log.ReplaceSel(strline);

//Put back Old Selection
m_log.SetSel(oldCharRange);
}


If you have any other questions, don't hesitate to ask!


May the MFC be with you!
jmmougeolle@calva.net strikes back!
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question