Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1242
  • Last Modified:

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

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
valentingalea
Asked:
valentingalea
  • 5
  • 4
  • 3
  • +1
2 Solutions
 
DanRollinsCommented:
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
 
valentingaleaAuthor Commented:
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
 
itsmeandnobodyelseCommented:
>>> 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
valentingaleaAuthor Commented:
I don't want the same menu, and yes I've checked the resources - everything is in order.
0
 
itsmeandnobodyelseCommented:
>>>> 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
 
valentingaleaAuthor Commented:
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
 
valentingaleaAuthor Commented:
Increased points! Answer and grab them while it's hot!:)
0
 
DanRollinsCommented:
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
 
valentingaleaAuthor Commented:
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
 
DanRollinsCommented:
The menus are set according to the view that is active.  If you want different menues, etc. then you should have different views.
0
 
AndyAinscowCommented:
>>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
 
itsmeandnobodyelseCommented:
>>>> 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
 
AndyAinscowCommented:
>>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
 
itsmeandnobodyelseCommented:
>>>> 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now