Solved

Carriage return in CRichEditCtrl

Posted on 1997-05-05
1
724 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
1 Comment
 
LVL 1

Accepted Solution

by:
jmmougeolle earned 50 total points
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 60
sum28 challenge 31 95
only14 challenge 19 63
Path of Workbook 3 44
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video discusses moving either the default database or any database to a new volume.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now