Visual C++ Developer Center > Visual C++ Forums > Visual C++ General > CRichEditView: Reading .txt and .rtf files
Ask a questionAsk a question
 

AnswerCRichEditView: Reading .txt and .rtf files

  • Wednesday, November 04, 2009 5:11 PMlesPaul456 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello,

    About two days ago I started working on a simple text editor using the MFC Feature Pack.

    Using the wizard, I created an application that uses CRichEditView as the base class. So far I have the ribbon complete. The last thing I'm working on is opening and saving files.

    I'm actually a C# programmer, and I have only limited experience in C++. In C#, file operations are very simple, usually requiring only a few lines of code...

    So far I have not added any code to save or open files. It seems the wizard took care of saving the files for me, since I can save a .rtf or .txt file perfectly fine. However, when I attempt to open a file, a new tab opens (it's a MDI application with tabbed documents) it's blank with no text.

    ...So I'm hoping that someone can give me some advice on how to read a file using a CRichEditView.

    Also, I should note that I'm not sure where I should even put this code. To format the documents, I added the code to the CRichEditView's cpp file. Would it be the same or would I use the CRichEditDoc?

    Thanks!

Answers

All Replies

  • Wednesday, November 04, 2009 5:27 PMNikita Leontiev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    As far as I understand, you should use StreamIn and StreamOut methods to read/write data to input/output streams.
    • Marked As Answer bylesPaul456 Wednesday, November 04, 2009 7:47 PM
    •  
  • Wednesday, November 04, 2009 5:44 PMlesPaul456 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    So would I just create an event handler for my "Open" button in the CRichEditView file and then call GetRichEditCtrl()->StreamIn() from that handler?

    Any idea why the wizard handles saving files for me, but not opening them?

    Thanks again for the help. I'll get back to you with my results later.

  • Wednesday, November 04, 2009 5:49 PMNikita Leontiev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Check the examples from msdn for both functions (links I have already provided).
    I don't know why wizards do not work correctly, because I don't know anything about them =)

  • Wednesday, November 04, 2009 7:47 PMlesPaul456 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Thanks for all the help.

    I got it to work by overriding the CRichEditDoc::OnOpenDocument method.
    • Marked As Answer bylesPaul456 Wednesday, November 04, 2009 7:47 PM
    •