Solved

Carriage return in CRichEditCtrl

Posted on 1997-05-05
1
755 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa‚Ķ
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.

735 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