Solved

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

Posted on 2009-05-16
15
1,108 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
ID: 24405923
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
ID: 24405985
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
ID: 24407906
>>> 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
ID: 24408311
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
ID: 24409260
>>>> 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
ID: 24410415
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
ID: 24415427
Increased points! Answer and grab them while it's hot!:)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 49

Accepted Solution

by:
DanRollins earned 135 total points
ID: 24417013
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
ID: 24417318
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
ID: 24418272
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
ID: 24419019
>>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
ID: 28322442
>>>> 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
ID: 28323630
>>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
ID: 28325109
>>>> 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
notReplace  challenge 53 116
countEvens challenge 2 78
either24  challenge 19 90
fix34  challenge 9 105
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 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

19 Experts available now in Live!

Get 1:1 Help Now