If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How To Handle An Open Document

First off I am still a noob so be nice

I have an MFC program created from the app wizard. It is an MDI program, reading/writing text files using Serialize. I can read the document and know that the entire document was read into my buffer without any errors. This was verified by compaing the number of bytes read with the file length.

How do I get the document to display in my main/child window?

How do I read the document from the window so I can save it back to the file?

Sample lines of code would be great!!

Thanks in advance for answering simple questions from a confused old fart

Re: How To Handle An Open Document

You display the document data neither in main nor in child window. You display it in one or more Views. And it is up to you to choose the types of the Views to display the document data.

If some data displayed in a View was changed then you can use CView::GetDocument method to access the document and change the corresponding data in it.

Save document data is just opposed to get it. If you use some type or ReadFile to read - then use corresponding WriteFile to write/save.
If you use CArchive class to read data (using operator <<()) then use operator >>() to save...

Re: How To Handle An Open Document

Hi Victor,

Thanks for the information and the link.

Since the document is not showing up in my window, what must I do to display it after reading it into memory? I have seen commands like UpdateAll() or UpdateView() (I think) but what must I do once the document is in memory. My window just remains blank.

Re: How To Handle An Open Document

If your view is derived from CView, you'll need to handle all the text rendering yourself, which would be a pain. A better idea would be to derive your view from CEditView and it should do everything for you.

Before I added the read routine, I was able to see my data in the window, line by line, after the file was read be the default MFC read/Serialize reader routine. Maybe I am not reading the file correctly or maybe some how I need to change a default pointer to where my data is stored in memory?

Re: How To Handle An Open Document

UpdateAllViews is used by the document to tell the view that something has changed and gives the view a chance to do whatever it needs to. I've never used the CEditView and you seem to be writing code outside of the Doc/View architecture, so just given that snipped, I can't tell you what's wrong. I can tell you it's best to let MFC do as much of the work as possible.

Re: How To Handle An Open Document

The code above should have showed CFooDoc::ReadFileData(void). It does reside in my Doc class.

I understand about the Wait cursor, thanks.

So, let's say I just delete the read file function all together. Now when I open a file it would be handled by the default, built in code. From what I am reading, if I use a pDoc->GetDocument() that will pull my file data into a variable which would allow me to manipulate it? Then how would I push it back to the Window as an updated document with changes that were made by other functions?

I know I must be making this harder than it needs to be. I just need to:

1. Open a file and read it into memory. That works by default.
2. How do I access that data directly so I can manipulate it?
3. How do I push those updates back to the screen so I can see them?
4. Then I would use GetDocument() to retrieve the data so it can be Serialized back to the disc.

Coding is a hobby. I learned assembly language as my first language on a 24-bit mainframe (SEL 840) that ran on a Flight Simulator. Then I progressed to a 16-bit Texas Instruments 980 computer, and eventually was able to exchange data between the computers. That seemed easy compared to what I am now trying to teach myself. I learn fast when I have an example that works. I have books, but just can't seem to find the right answer to getting this to work. Been at it for a few weeks now and have learned a lot, just not what I need

Re: How To Handle An Open Document

I just used the wizard to create a new app with CEditView as the base class. I wrote no code at all. I compiled it, ran it and opened a text file. It displayed it properly. Again, I didn't write a single line of code. The framework did it all.

Re: How To Handle An Open Document

Yes, I agree with the wizard and that it works. No arguments. But I still don't understand how to manipulate the data.

I have a parse routine created and works on test data. So when I open a file and read it (using the default wizard code), I need to be able to manually manipulate that code. I want to parse it, put it in say 10 different variables, make changes to it and send it back to the screen (all through functions and not direct interface with the users). The idea is I am reading the data, validating it and if it is incorrect, I am making the change, after it has been read, and then updated on the screen to show the change.

I can parse the data using a test file. It works.

Do I use GetDocument() to pull the data down from the window so I can then parse/process it manually? If so, how do I execute that comand? Is it something like:

Code:

CDocument* myDoc = pDoc->GetDocument();

Then does my data reside in myDoc and I can parse it?

Once my data is parsed, how do Ipush myDoc back into the window so it shows the updated value?

Re: How To Handle An Open Document

Again, I haven't worked with the CEditView, but looking at the documentation, it looks like you'd call GetEditCtrl from the view class to get its edit control, then use the various CEdit or CWnd functions to get and manipulate the text. GetWindowText() would get you all the text in the edit control and put it in a CString. You could do what you want with it from there, then use SetWindowText() to update the edit control with the new text.

It appears in this case, the CEdit control actually maintains the text and the doc is just used to transfer it between the window and the file.

Re: How To Handle An Open Document

Do I use GetDocument() to pull the data down from the window so I can then parse/process it manually? If so, how do I execute that comand? Is it something like:

Code:

CDocument* myDoc = pDoc->GetDocument();

GetDocument() is a method of CView class, not a CDocument one.
It is used to get/set data from/to Document instance to/from View instance.
Document instance itself should not ever try to directly access any View instance.