Click to See Complete Forum and Search --> : CEdit multiline text read in from file
KenSV
June 7th, 1999, 05:48 PM
I'm trying to use a mulitline edit box as a static text display. But when I read in the text into the box, from file, the carriage return shows up as a thick bar character and the box line wraps the text wherever. Is there a way to make the CEdit control wrap on CR or do I need a third party "memo" control. I'm using MSVC++ 6.0.
Thanks,
Ken
tdg
June 7th, 1999, 07:18 PM
In CEdit's you need both carriage return and linefeed: \r\n
KenSV
June 8th, 1999, 11:33 AM
All the lines do have a carriage return, line feed combination.
I'm reading from a file into a character array and then calling SetWindowText to apply
the text to the editbox. Instead of correctly interpreting the carriage return/line feed, the
editbox prints a thick bar character and word wraps wherever it likes.
There must be a way either with CEdit or with another control to do this. I'm simply trying
to display static text, read in from a file. Anyone?
Todd Jeffreys
June 8th, 1999, 11:37 AM
Listen to tdg. '\n' must be replaced by '\r\n'. So i suggest you read one character at a time, and when you read a '\n' put "\r\n" into your buffer and keep going
tdg
June 8th, 1999, 02:14 PM
Your file may have carriage return and linefeeds, but are you sure your buffer does? I kind of doubt it. I've done this enough times to know that \r\n works fine and \n alone gives that funny bar symbol. Depending on how you read your file, the routine may automatically strip out the \r.
KenSV
June 8th, 1999, 04:42 PM
Thanks, it worked. You were correct, the Read function strips the carriage return out. I replaced it as you suggested and the edit box looks beautiful.
Sam Hobbs
June 8th, 1999, 08:37 PM
Yes, listen to tdg. How you read your file is important. The following works for me:
BOOL CDataDlg::OnInitDialog() {
CFileException FileExc;
CFile Inputfile;
DWORD n;
CDialog::OnInitDialog();
if (!Inputfile.Open("C:\\CONFIG.SYS", CFile::modeRead, &FileExc))
return TRUE;
n = __min(Inputfile.GetLength(), INT_MAX);
n = Inputfile.Read(m_FileData.GetBuffer(n), n);
m_FileData.ReleaseBuffer(n);
Inputfile.Close();
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.