CRichEditView: Reading .txt and .rtf files
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
- 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
- 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
All Replies
- 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
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.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 =)- 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


