CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 1999
    Location
    Sacramento, California
    Posts
    7

    CEdit multiline text read in from file

    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


  2. #2
    Join Date
    Apr 1999
    Posts
    52

    Re: CEdit multiline text read in from file

    In CEdit's you need both carriage return and linefeed: \r\n



  3. #3
    Join Date
    Jun 1999
    Location
    Sacramento, California
    Posts
    7

    Re: CEdit multiline text read in from file

    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?


  4. #4
    Join Date
    Apr 1999
    Posts
    396

    Re: CEdit multiline text read in from file

    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


  5. #5
    Join Date
    Apr 1999
    Posts
    52

    Re: CEdit multiline text read in from file

    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.



  6. #6
    Join Date
    Jun 1999
    Location
    Sacramento, California
    Posts
    7

    Re: CEdit multiline text read in from file

    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.


  7. #7
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266

    Re: CEdit multiline text read in from file

    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
    }





    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured