Dynamically changing menu in MDI app 
Author Message
 Dynamically changing menu in MDI app

I've got a typically MFC AppWizard generated MDI application.
I have only one document type, one menu resource (okay, actually two if you
count the one that App wizard generates).

So what I want to be able to do is to update the items on one of the menus.
The problem I'm having is that the CMainFrame window has the normal,

FILE | EDIT |VIEW|WINDOW|HELP

menu and my MDI documents have the same menu with an additional "TOOLS"
menu.
I only want the tools to show up when the documents are open.

So far, no problem.

The problem is based on the kind of file I open, I want to add different
tools to the TOOLS menu, and have those tools reflected on the toolbar.

The problem is that the toolbar isn't showing up properly, and the reason is
because until I actually Click on the TOOLS menu and cause it to be
customized, it isn't actually customized. Hence the icons are greyed. :(

How can I "catch" the menu when it changes from the default menu to the MDI
menu so I can customize it before a user ever clicks on it? Or am I rambling
too much. <g>

Bob Cozzi



Sat, 27 Sep 2003 04:26:57 GMT  
 Dynamically changing menu in MDI app
I didn't really follow everything you said.  If you add a new document
template as follows:

 m_pDocTemplateLis = new CMultiDocTemplate(
        IDR_LISTYPE,
        RUNTIME_CLASS(CLISDoc),
        RUNTIME_CLASS(CChildFrame), // custom MDI child frame
        RUNTIME_CLASS(CLISView));
 AddDocTemplate(m_pDocTemplateLis);

Then create a menu resource with an ID of IDR_LISTYPE.  When you start your
application up the menu IDR_MAINFRAME should be displayed.  Then when you
open a document of type IDR_LISTYPE, the menu IDR_LISTYPE will be displayed.

You first said that "I have only one document type" but then you said "The
problem is based on the kind of file I open, I want to add different tools
to the TOOLS menu".  So which is it?  Do you have one document type or
multiple document types.  If you have multiple type, just add them as shown
above and the menus will switch automatically for you!  Its magic!  By the
way, you will also need to add string resources for the types (IDR_LISTYPE)
so that the frame work know something about the documents (i.e. its
extension).

I hope this helps.  If you are struggling too much, then you are doing
something wrong.  If you follow the Doc/View architecture properly,
everything should go smoothly!

Don Sanders



Sat, 27 Sep 2003 06:10:37 GMT  
 Dynamically changing menu in MDI app
If you use multiple document templates, then I need to duplicate the menu
options, create new icons, string table entries etc.

What I have is effectively a file viewer that can read any type of file
(from a mainframe) and display it. I want to simply add a few menu option to
the TOOLS menu when a file of a certain type is displayed. But other than
that, everything is identical. I don't want to manage multiple document
templates simply because of the fact that if I change the "EDIT" menu (for
example) I have to change the EDIT menu on each and every other document
template.

Bob


Quote:
> I didn't really follow everything you said.  If you add a new document
> template as follows:

>  m_pDocTemplateLis = new CMultiDocTemplate(
>         IDR_LISTYPE,
>         RUNTIME_CLASS(CLISDoc),
>         RUNTIME_CLASS(CChildFrame), // custom MDI child frame
>         RUNTIME_CLASS(CLISView));
>  AddDocTemplate(m_pDocTemplateLis);

> Then create a menu resource with an ID of IDR_LISTYPE.  When you start
your
> application up the menu IDR_MAINFRAME should be displayed.  Then when you
> open a document of type IDR_LISTYPE, the menu IDR_LISTYPE will be
displayed.

> You first said that "I have only one document type" but then you said "The
> problem is based on the kind of file I open, I want to add different tools
> to the TOOLS menu".  So which is it?  Do you have one document type or
> multiple document types.  If you have multiple type, just add them as
shown
> above and the menus will switch automatically for you!  Its magic!  By the
> way, you will also need to add string resources for the types
(IDR_LISTYPE)
> so that the frame work know something about the documents (i.e. its
> extension).

> I hope this helps.  If you are struggling too much, then you are doing
> something wrong.  If you follow the Doc/View architecture properly,
> everything should go smoothly!

> Don Sanders




Sat, 27 Sep 2003 14:33:14 GMT  
 Dynamically changing menu in MDI app
There are couple of ways to handle issues such as these.  One is to handle
OnInitMenuPopUp in your MDI main frame. This may not help you because you
want to put something in the menubar itself. That leaves you with the option
of tracing the menu swapping in OnMDIActivate(). Simple option would be to
just access the menus in each of the MDI doctemplates and change it as you
want. Responsibility of managing it would be totally up to you.

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.


Quote:
> I've got a typically MFC AppWizard generated MDI application.
> I have only one document type, one menu resource (okay, actually two if
you
> count the one that App wizard generates).

> So what I want to be able to do is to update the items on one of the
menus.
> The problem I'm having is that the CMainFrame window has the normal,

> FILE | EDIT |VIEW|WINDOW|HELP

> menu and my MDI documents have the same menu with an additional "TOOLS"
> menu.
> I only want the tools to show up when the documents are open.

> So far, no problem.

> The problem is based on the kind of file I open, I want to add different
> tools to the TOOLS menu, and have those tools reflected on the toolbar.

> The problem is that the toolbar isn't showing up properly, and the reason
is
> because until I actually Click on the TOOLS menu and cause it to be
> customized, it isn't actually customized. Hence the icons are greyed. :(

> How can I "catch" the menu when it changes from the default menu to the
MDI
> menu so I can customize it before a user ever clicks on it? Or am I
rambling
> too much. <g>

> Bob Cozzi



Sat, 27 Sep 2003 14:50:03 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. MDI Menus - how to change dynamically?

2. Dynamically changing menus in an MDI application

3. dynamically changing MDI MainFrame menu

4. Dynamically changing main window title bar for an MDI app

5. Dynamically changing top-level menu in SDI app?

6. changing the main frame menu in MDI app

7. Changing menus in a MDI app

8. Adding menu items to an MDI app menu?

9. Can't change app and view icons in a VC++ 5 MDI App

10. Dynamically Customizing MDI menus

11. changing controls dynamically on a MDI window

12. Dynamically change a menu label

 

 
Powered by phpBB® Forum Software