Solved

Carriage return in CRichEditCtrl

Posted on 1997-05-05
1
760 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 50 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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