Solved

VS2010 C++ MDI with two sets of toolbar and menus

Posted on 2011-02-25
6
550 Views
Last Modified: 2012-05-11
I am looking for an example program that has the following:

VS2010 C++ MDI program with two different kind of child windows: Child1 and Child2
Each child window has its own toolbar and  menu set
File/NEW1 will create the Child1 with toolbar1 with menu1
File/NEW2 will create the Child2 with toolbar2 with menu2

Because VS2010 MDI project always creates one set of window with toolbar. I have a hard time figuring out how to add an additional different child window with different toolbar.  

Thanks.
0
Comment
Question by:BaritoneH
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:cup
ID: 34985938
What type of project is it?  VS can generate forms for different project types.  The ones I know of are

unmanaged SDK
MFC
WTL
managed Winforms stuff
0
 

Author Comment

by:BaritoneH
ID: 34986392
The project is C++ with MFC. Just the basic MFC, nothing extra.
0
 
LVL 32

Expert Comment

by:sarabande
ID: 34998160
an MDI app is a multi-document application what means that you would need to add a second doument class to the project.

in InitInstance of your application class you would create an additional triple of document, frame and view:

    m_pTemplate1 = new CMultiDocTemplate(
        IDR_FIRST,
        RUNTIME_CLASS(CMyDoc1),
        RUNTIME_CLASS(CMyChildFrame),        // standard MDI child frame
        RUNTIME_CLASS(CMyView1));
    AddDocTemplate(m_pTemplate1);
                                                                                               
    m_pTemplate2 = new CMultiDocTemplate(
        IDR_SECOND,
        RUNTIME_CLASS(CMyDoc2),
        RUNTIME_CLASS(CMyChildFrame),        // standard MDI child frame
        RUNTIME_CLASS(CView2));
    AddDocTemplate(m_pTemplate2);

The IDR_FIRST and IDR_SECOND are resource ids where you bind the menu and toolbar.

Sara
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:BaritoneH
ID: 34999319
Thanks for the note.

I created an example MFC MDI project in VS2010 and then I add two classes CDoc2 and CView2. Duplicated the menu1 and toolbar1 to menu2 and toolbar2. Initialized the m_pTemplate2.  I can switch the menu, but I am still having trouble switching the toolbar in CView2.  Do I need to do anything about the m_wndTooBar?

The m_wndToolBar was created in the MainFrm::OnCreate.  Does it need to be assigned to different toolbar in ChildFrame?  It would be great if I can get a working examples. Thanks.
0
 
LVL 32

Accepted Solution

by:
sarabande earned 500 total points
ID: 34999457
yes, the toolbar 'normally' isn't supposed to change but only the menus.

but you could make two 'mdichildwnd' frame classes where each of them installs an own toolbar (exactly removes or minimizes current toolbar and restores or creates new toolbar).

you also could use mainframe to take the switch. add a second member m_wndToolBar2 and create it using the second resource but not show it.  then when the menu was switched call a new member function of CMainFrame which would exchange the toolbars. you can access CMainFrame object from everywhere for example by

  ((CMainFrame*)AfxGetMainWnd())->switchToolbar(2);

if you would use two frame classes you would install the proper toolbar when the frame was activated and the OnInitialUpdate override was called.

Sara
0
 

Author Closing Comment

by:BaritoneH
ID: 35001304
Thanks for the help!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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

22 Experts available now in Live!

Get 1:1 Help Now