Solved

Can I have multiple top level windows of different content under MFC Doc/View?

Posted on 2009-05-16
15
1,088 Views
Last Modified: 2013-11-20
I have this MDI based application written using MFC Doc/View paradigm, and I want to 'spawn' several top-level SDI frame windows (within the same process). These so called helpers will DIFFER from the main app child windows as they will display different views, menus, toolbars.

Now when I spawn the helpers using:

CMultiDocTemplate::CreateNewDocument();
CMultiDocTemplate::CreateNewFrame(pDoc, NULL);

it works as expected but the MFC framework then treats these new frames as some sort of MDI children of the main application! So for example, closing one of them will change the menubar and garble the toolbar buttons of the main application.

What's happening? Am I forcing the framework? How can I have multiple top-level frame windows along a main MDI one?

Thanks!
CMultiDocTemplate *pDocTemplate = new CMultiDocTemplate(

        IDR_MENU,

        RUNTIME_CLASS( CDoc ),

        RUNTIME_CLASS( CChildFrame ),

        RUNTIME_CLASS( CView ) );

if( !pDocTemplate )

        return FALSE;

AddDocTemplate( pDocTemplate );
 

CMultiDocTemplate *pDocTemplate2 = new CMultiDocTemplate(

        IDR_MENU2,

        RUNTIME_CLASS( CDoc2 ),

        RUNTIME_CLASS( CMainFrame ),

        RUNTIME_CLASS( CView2 ) );

if( !pDocTemplate2 )

        return FALSE;

Open in new window

0
Comment
Question by:valentingalea
  • 5
  • 4
  • 3
  • +1
15 Comments
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Have You called:
    CDocTemplate::InitialUpdateFrame
    http://msdn.microsoft.com/en-us/library/hf259e95.aspx
Have you called
    CDocTemplate::GetDocString
    http://msdn.microsoft.com/en-us/library/2b4xctyw.aspx
to verify that the correct resource data has been used?
0
 

Author Comment

by:valentingalea
Comment Utility
Thanks for the comment!
Here is the code I use to spawn the frames:

	// Create a new instance of the document referenced

	// by the m_pDocTemplate member. 

	pDoc = m_pDocTemplate->CreateNewDocument();

	if (pDoc != NULL)

	{

		// If creation worked, use create a new frame for

		// that document.

		pFrame = m_pDocTemplate->CreateNewFrame(pDoc, NULL);

		if (pFrame != NULL)

		{

			// Set the title, and initialize the document.

			// If document initialization fails, clean-up

			// the frame window and document.

			

			m_pDocTemplate->SetDefaultTitle(pDoc);

			if (!pDoc->OnNewDocument())

			{

				pFrame->DestroyWindow();

				pFrame = NULL;

			}

			else

			{

				// Otherwise, update the frame

			m_pDocTemplate->InitialUpdateFrame(pFrame, pDoc, TRUE);

			}

		}

	}

Open in new window

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
>>> So for example, closing one of them will change the menubar and garble the toolbar buttons of the main application.

Check your resources. For each document type in a MDI there is an own IDR_  resource. If you want only one you better had made a SDI but you also could assign the IDR_MAINFRAME to all 'documents' thus getting the same menu and associated tool-bar to all documents.
0
 

Author Comment

by:valentingalea
Comment Utility
I don't want the same menu, and yes I've checked the resources - everything is in order.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
>>>> I don't want the same menu,
No? But the toolbar buttons were associated ith the menus? And if you have different menus it necessarily needs to change them after closing a document and making some other the active one.
0
 

Author Comment

by:valentingalea
Comment Utility
Let me rephrase the question:

I have a main MDI based application, how can I have separate (i.e. not MDI children of main window)  top-level frames (i.e. composed of menubar, toolbar, view)?

Of course I'm not looking for the obvious method of having separate exe that I call:)
0
 

Author Comment

by:valentingalea
Comment Utility
Increased points! Answer and grab them while it's hot!:)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 49

Accepted Solution

by:
DanRollins earned 135 total points
Comment Utility
When you started this project, did you select  "Multiple top-level documents" as the Application type?
As you create new CView-derived objects, were you sure to select the Generate DocTemplate resources checkbox in the MFC Class Wizard?
Theres a good article here
    Multiple Top Level Windows
     http://www.codeproject.com/KB/docview/multitop.aspx
that should answer some of your questions.  
BTW, 135 points makes this the lowest-valued question on the list :-)
0
 

Author Comment

by:valentingalea
Comment Utility
All the "Multiple top-level documents" examples on the web and also the generated Visual Studio code deal with same frame document templates. They spawn the same type of top-level doc/views, this is exactly what I DON'T want.

I use Visual C++ 2005 - there is no "Generate DocTemplate resources" option.

As for the points, I was awarded 300 points for answering a question and I blindly rushed to use them here, but it didn't work!:) Sorry for the false incentive!
0
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 135 total points
Comment Utility
The menus are set according to the view that is active.  If you want different menues, etc. then you should have different views.
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
>>how can I have separate (i.e. not MDI children of main window)  top-level frames (i.e. composed of menubar, toolbar, view)?how can I have separate (i.e. not MDI children of main window)  top-level frames (i.e. composed of menubar, toolbar, view)?

That as far as I know is not a default supported way of doing things in MFC - in other words it involves a LOT of coding of your own.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
>>>> The menus are set according to the view that is active.
In a MDI application the document (type) would rule the menu. Not the view.
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
>>In a MDI application the document (type) would rule the menu. Not the  view.

Yes, and no.  One view per doc - doc should control.  Splitter window onto one doc - what is possible is view dependant.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
>>>> Yes, and no.  

You surely can manage menus differently for views but the doc (and doc template) is the mechanism the MFC framework has as a default. See the following sample code where the  IDR_NOTETYPE is the resource for the menus and the toolbar.

        AddDocTemplate( new CMultiDocTemplate( IDR_NOTETYPE,
                            RUNTIME_CLASS( CNoteDoc ),
                            RUNTIME_CLASS( CMDIChildWnd ),
                            RUNTIME_CLASS( CNoteView ) ) );
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now