MFC Document/View - New Milestone :: C++

kuphryn

Senior member
Jan 7, 2001
400
0
0
Hi.

I began and finished reading chapter 9 of Promise's book on MFC today. I believe I have reached a milestone in the journey to become a proficient...good MFC programmer.

Here is what I know.

MFC = application object->frame window->view->documents

Promise emphasized that documents as an abstract concept object including data. I interpret documents as dealing with the program's "purpose" i.e. program theme.

Nonetheless, I have not come to a complete understanding as to what comes first: view or documents. For example, as program designer and developers, we should always walk the steps of a program user. I am not completely sure as to where is the clear separation of view and documents, event though view is the program interpreter. View does the drawing according to the data from documents.

For example, let say I am working on a program that reads data from a file and puts it on a window in *binary* mode. Let say I create three classes using AppWizard and ClassWizard:

1) ConceptPro (mainframe window)
2) view
3) document

First, the classes above are MFC's generated classes.

Conception is the application object and it handles all the taskbar, menu, etc.

View draws the childframe, *binary* data from a file, etc.

Documents handles the data such as filename, file data, etc.

Is the description above valid? Please point out where I am "going off track" or "missed something important."

Lastly, let say I have other classes that manipulate the data in the file *before* outputing it. Where should I instantiate these classes in documents or in view? I am not completely clear as to rank of document and view.

Thanks,
Kuphryn
 

RSMemphis

Golden Member
Oct 6, 2001
1,521
0
0
The view is normally used to redraw the window - it needs to fetch data from the document, so you need a member of the document object that returns pointers to your data.
The mainframe object is for the box surrouding your view, where you can set menus and toolbars
The document is where you SHOULD store your data (you could store the data in the view), because it has some members that will help you when storing the data, for example serialization.

Other class should be generated from scratch - you only want one document and one view (unless you have multiple views).
If your new class should be serializable, create it from CObject.
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
Thanks.

As I mentioned in the topic of "New Milestone," document/view architecture has shine light on my understanding of MFC. It gave me confident to push further (finish the book), and along the way, begin to take pay close attention and take notes for future projects (implement my C++ programs using MFC). I am not quite to that point yet, but MFC is beginning to come together nicely relative to my learning MFC.

-----

Multiple view per document: (AsmGuru62 and TrojanGekko also brought up this issue at programmersheaven and cprogramming)

Lets consider the example AsmGuru62 mentioned about formatting data in text and HEX. As of chapter 10 in Prosise' book, he has not brought up the concept of multiple view. He did mention multiple documents as an upcoming topic, but not multiple view.

First, for multiple view, do you approach it exactly the same way as singular view? Do you use ClassWizard to add a new derivative of CView or one of CView's derivative (scroll, etc.)?

-----

I am at a point with MFC where I see the *lego* pieces, but I have limited experience assembling the pieces together. That includes mapping related commands to related class derivatives, etc. I believe that comes with experience.

Kuphryn