• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

MultiDocument And MultView (and per document) :: MFC

kuphryn

Senior member
Hi.

I created the core program in doc/view architecture. I understand that the idea behind doc/view is one document for each view. A document could have more than one view, but a view can only display one document, period.

Let consider I have a program that deals with text and document format. For example, I can open edit text for (*.txt) and document file (*.doc). If I am correct, I would need two document classes (derived) and at least two view. Right? If yes, what is the how do I add a new document class into the program *and link* it with a *new/different* view class? I have been using the AppWizard to generate a doc/view. I have never added a new document and a view with it.

Thanks,
Kuphryn
 
To make everything clear, I am using doc/view *single* document. I am using single document because at anytime in the program, one one document is active. To my understanding, multiple document means the user can work with multiple documents at one time similar to how the user can open, view, and edit more than one images in Photoshop.

Anyways, here is the default core document template straight from a freshly generated MFC application:

-----
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.

CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMultiDocDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CMultiDocView));
AddDocTemplate(pDocTemplate);
-----

I added a *two* new classes. One was derived from CDocument. The second was derived from CEditView The name of the class was "CMultiDocAct1."

New class: CMultiDocAct1Doc (derived from CDocument)
New class: CMultiDocAct1View (derived from CEditView)

Is the following correct?

-----
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.

CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMultiDocDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CMultiDocView));
AddDocTemplate(pDocTemplate);

// I added the following

CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMultiDocAct1Doc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CMultiDocAct1View));
AddDocTemplate(pDocTemplate);

-----

All I did was added the names of the two new classes.

Lastly, I need to access the *new document* class from a view class, most likely the new view class (CMultiDocAct1View). I noticed the following code was in the original AppWizard generated view class:

-----
#ifndef _DEBUG // debug version in MultiDocView.cpp
inline CMultiDocDoc* CMultiDocView::GetDocument()
{ return (CMultiDocDoc*)m_pDocument; }
#endif
-----

Do I need to add something similar to the new view class?

Thanks,
Kuphryn
 
Back
Top