Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Carriage return in CRichEditCtrl

Posted on 1997-05-05
1
Medium Priority
?
807 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

604 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