Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CRichEditView: Read .txt and .rtf files

52 views
Skip to first unread message

lesPaul456

unread,
Nov 4, 2009, 2:17:01 PM11/4/09
to
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!

AliR

unread,
Nov 4, 2009, 3:33:32 PM11/4/09
to
Are you sure that it saves as txt file? The default implementation of
CRichEditDoc/CRichEditView is to write out RTF.

As far as opening, it should have had the open code already there for you.
The message map for your CWinAppEx derived class should have an entry for
ID_FILE_OPEN, see if points to CWinAppEx::OnFileOpen.

Otherwise, how many different CMultiDocTemplates do you have in your
project? Are you catching the ID_FILE_OPEN anywhere else beside CWinAppEx
derived class?


AliR.


"lesPaul456" <lesPa...@discussions.microsoft.com> wrote in message
news:F0C8DFCD-FEE0-432E...@microsoft.com...

DanB

unread,
Nov 4, 2009, 4:30:06 PM11/4/09
to
lesPaul456 wrote:
> Hello,

>
>
> 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.

So, when you open this saved file in wordpad you see your rich text doc?

> 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?

Not sure what you did as you should have a doc derived from CRichEditDoc
and serialize should be pushed through like:

void CMyDoc::Serialize( CArchive& ar )
{
CRichEditDoc::Serialize( ar );
}

And that ends up with a:
pView->Serialize( ar );

Did you leave all this code in place?

Set a break point at Serialize and see where it takes you. You must end
up in Stream(...) to read and write rtfs.


Best, Dan.

0 new messages