Solved

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

Posted on 2011-02-25
6
552 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 33

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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 33

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 197
topping2 challenge 13 83
HP PC Hardware Diagnostics UEFI 11 118
Asus ks2003 driver XP 32 33 117
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

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