mfc >> Multiple views Single Document MDI - no splitter views

by ggurubasavaraja » Sat, 18 Aug 2007 17:21:54 GMT

Hi Folks,

I have a situation where I need 4 views in my application. All the 4
views should co exist and shall be updated independently/
simultaneously.

I searched the forum and all I got was how to create multiple views
for a SDI and for MDI creating multiple document templates and make
them refer to a single document .

I dont know whether creating multiple document templates is a good
solution as I read somewhere it is not an optimal solution.

Is there any simple/optimal method by which I can go on adding a view
for the document? If possible please paste a link to the sample
application.

Thanks in Advance.

Regrads,
JustLikeDat


mfc >> Multiple views Single Document MDI - no splitter views

by ggurubasavaraja » Sat, 18 Aug 2007 17:21:57 GMT


Hi Folks,

I have a situation where I need 4 views in my application. All the 4
views should co exist and shall be updated independently/
simultaneously.

I searched the forum and all I got was how to create multiple views
for a SDI and for MDI creating multiple document templates and make
them refer to a single document .

I dont know whether creating multiple document templates is a good
solution as I read somewhere it is not an optimal solution.

Is there any simple/optimal method by which I can go on adding a view
for the document? If possible please paste a link to the sample
application.

Thanks in Advance.

Regrads,
JustLikeDat

mfc >> Multiple views Single Document MDI - no splitter views

by Joseph M. Newcomer » Sun, 19 Aug 2007 01:18:27 GMT

have a "sanitized" version of some code I did a few years ago that I put together for
this. Send me a private email and I'll send you a copy. The quick summary is below.

I did this from the mainfrm.cpp file. The code goes like this:

Add a protected variable to the mainframe class:

CMultiDocTemplate * GreenTemplate;

In the CMainFrame::CMainFrame constructor, clear it out
GreenTemplate = NULL;
Add a new protected class member function
CDocument * GetCurrentDocument();
For symmetry, I added an additional variable
CMultiDocTemplate * RedTemplate;
and set it to NULL as well.

Create a new CView-derived class, in my case CGreenView (the names have been sanitized to
protected certain secure information).

The default view is a Red view, as exemplified by the standard InitInstance code:

pDocTemplate = new CMultiDocTemplate(IDR_RedViewTYPE,
RUNTIME_CLASS(CMultiViewDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CRedView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);


I added the following:

a new menu

IDR_GreenViewTYPE=xxx

where xxx is a resource number you have not already used. In my case it was 130. It has
to have an ICON of that ID, and a STRINGTABLE resource of that ID, so the ID numeric value
cannot be used already in either a string, icon, or menu context.

I added to the Window menu of the exisiting IDR_RedViewTYPE the item
&Green View = ID_WINDOW_GREENVIEW
and to the new menu for the IDR_GreenViewTYPE the item
&Red View = ID_WINDOW_REDVIEW


I Created an icon of the ID IDR_GreenTYPE.

In mainfrm.cpp, I added the handler to create a Green View:

CDocument * CMainFrame::GetCurrentDocument()
{
CMDIFrameWnd * frame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
if(frame == NULL)
return NULL;
CMDIChildWnd * child = (CMDIChildWnd *)frame->GetActiveFrame();
if(child == NULL)
return NULL;
CView * view = child->GetActiveView();
if(view == NULL)
return NULL;
CDocument * doc = view->GetDocument();
return doc;
} // CMainFrame::GetCurrentDocument

void CMainFrame::OnWindowGreenview()
{
if(GreenTemplate == NULL)
GreenTemplate = new CMultiDocTemplate(IDR_GreenViewTYPE,
RUNTIME_CLASS(CMultiViewDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CGreenView));

CMultiViewDoc * doc = (CMultiViewDoc *)GetCurrentDocument();
CFrameWnd * frame = GreenTemplate->CreateNewFrame(doc, NULL);
if(frame != NULL)
{ /* frame created */
frame->InitialUpdateFrame(doc, TRUE);
} /* frame created */
}

void CMainFrame::OnUpdateWindowGreenview(CCmdUI *pCmdUI)
{
CMultiViewDoc * doc = (CMultiViewDoc *)GetCurrentDocument();
pCmdUI->Enable(doc != NULL);
}

And one for a Red view:

void CMainFrame::OnWindowRedview()
{
if(RedTemplate == NULL)
RedTemplate = new CMultiDocTemplate(IDR_RedViewTYPE,
RUNTIME_CLASS(CMultiViewDoc),
RUNTIME_CLASS(CChildFrame),

Similar Threads

1. Creating Multiple Splitter Views in a Single Document MFC project

I have created a new MFC project, with the application type being
"single document" type. While I have been able to create 4 views as
well as 2 views with ease, I have had a lot of trouble creating
splitters for 3 views. Is there any easy way of creating 3 views in
this type of MFC project? Thanks.

2. Multiple views Single Document MDI

3. looking for sample:multiple view single document in C# or VB

Hi,
I am looking for sample of an application similar to outlook regarding UI

when user select a tree node in the left pane a view is changed in the right
pane

(it does not necessarily support  MFC doc view architecture )

thanks in advance


4. multiple view single document

5. Multiple Views: how to open both views at startup or on new document

Following the CHKBOOK sample in MSDN I finally have two
different views associated with the same document, and working
simultaneously. The problem is that when I run my program I
only get the first view. The second view only appears when I
*open* a document from a file, and not when I start a new one.

The cause is no wonder, because the piece of code that opens
the second view is only inside the OpenDocumentFile() function.
That makes sense in the sample, which is designed to work always
on a file (either is opens an existing file, or it creates a new
one).

Q: What code should I add where, for my application to open both
views on a *new* document?

Furthermore, I have learnt that you can resize a view by calling
its parent frame's MoveWindow() function. I would like to size
each of my two views to a certain desired size at startup. What is
the appropriate place to add this code?

6. Multiple view for one document in MDI application - VC MFC

7. Seperate document for Splitter views

Hi
My app shows 2 graph views seperated by a splitter.

The base graphview class is the same say CGraphView

if i use
splitter.CreateView(0,0,RUNTIME_CLASS(CGraphView)...
splitter.CreateView(0,1,RUNTIME_CLASS(CGraphView)...

they both use the same document class

but i need them to show graphs frm different docs

if i make 2 objects of the CGraphView
how can i use the objects as CRuntimeClass*???
is there any other solution.

rgds
fordge


8. Multiple Views Without Splitter