Link to home
Start Free TrialLog in
Avatar of valentingalea
valentingalea

asked on

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

Avatar of DanRollins
DanRollins
Flag of United States of America image

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?
Avatar of valentingalea
valentingalea

ASKER

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

>>> 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.
I don't want the same menu, and yes I've checked the resources - everything is in order.
>>>> 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.
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:)
Increased points! Answer and grab them while it's hot!:)
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>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.
>>>> 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.
>>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.
>>>> 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 ) ) );