Dynamic Menu Creation in MDI App 
Author Message
 Dynamic Menu Creation in MDI App

Hello Netlanders,
I have to dynamically create a menu for my MDI App.When i use GetMenu() on
the OnCreate() handler in the CMainFrame class it gets the mainframe menu
i.e IDR_MAINFRAME.I want to modify the IDR_<appname>TYPE menu.If i modify it
using LoadMenu() in the OnCreate() Handler i dont see any change.What i have
to do to modify the menu and where to place the code.The code snippet is
int count;
        char temp[13];
        CMenu *pMenu = new CMenu();
        CMenu *sMenu = new CMenu();

        if(pMenu->LoadMenu(IDR_IETYPE))
                pMenu = pMenu->GetSubMenu(3);
        count = pMenu->GetMenuItemCount();
        wsprintf(temp,"%d",count);
        MessageBox(temp);
        if(pMenu)
        {
                pMenu->AppendMenu(MF_STRING|MF_ENABLED,ID_MENU,"Naveen");
                MessageBox("Menu Appended");
        }
        count = pMenu->GetMenuItemCount();
        wsprintf(temp,"%d",count);
        MessageBox(temp);
        DrawMenuBar();
        pMenu->DestroyMenu();



Tue, 01 Nov 2005 01:33:09 GMT  
 Dynamic Menu Creation in MDI App

Quote:
>I have to dynamically create a menu for my MDI App.When i use GetMenu() on
>the OnCreate() handler in the CMainFrame class it gets the mainframe menu
>i.e IDR_MAINFRAME.I want to modify the IDR_<appname>TYPE menu.If i modify it
>using LoadMenu() in the OnCreate() Handler i dont see any change.

An MDI application reloads the document menu when the active MDI
window changes - so presumably that's why you don't see your changes.

I'm not sure of the details, but presumably MFC reloads the menu after
processing the WM_MDIACTIVATE message.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



Tue, 01 Nov 2005 15:16:24 GMT  
 Dynamic Menu Creation in MDI App
You have to modify the menu of the corresponding doctemplate. This menu
handle is a public member of CMultiDoctemplate(m_hMenuShared).

--
Ajay Kalra [MVP - VC++]


Quote:
> Hello Netlanders,
> I have to dynamically create a menu for my MDI App.When i use GetMenu() on
> the OnCreate() handler in the CMainFrame class it gets the mainframe menu
> i.e IDR_MAINFRAME.I want to modify the IDR_<appname>TYPE menu.If i modify
it
> using LoadMenu() in the OnCreate() Handler i dont see any change.What i
have
> to do to modify the menu and where to place the code.The code snippet is
> int count;
>         char temp[13];
>         CMenu *pMenu = new CMenu();
>         CMenu *sMenu = new CMenu();

>         if(pMenu->LoadMenu(IDR_IETYPE))
>                 pMenu = pMenu->GetSubMenu(3);
>         count = pMenu->GetMenuItemCount();
>         wsprintf(temp,"%d",count);
>         MessageBox(temp);
>         if(pMenu)
>         {
>                 pMenu->AppendMenu(MF_STRING|MF_ENABLED,ID_MENU,"Naveen");
>                 MessageBox("Menu Appended");
>         }
>         count = pMenu->GetMenuItemCount();
>         wsprintf(temp,"%d",count);
>         MessageBox(temp);
>         DrawMenuBar();
>         pMenu->DestroyMenu();



Wed, 02 Nov 2005 01:15:07 GMT  
 Dynamic Menu Creation in MDI App
another way is to override the undocumented virtual function
CDocument::GetDefaultMenu() to allow the document to determine which menu to
display.
Knowledge Base
Q145857 How to Use Multiple Menus in MFC App That Uses GetDefaultMenu



Quote:
> Hello Netlanders,
> I have to dynamically create a menu for my MDI App.When i use GetMenu() on
> the OnCreate() handler in the CMainFrame class it gets the mainframe menu
> i.e IDR_MAINFRAME.I want to modify the IDR_<appname>TYPE menu.If i modify
it
> using LoadMenu() in the OnCreate() Handler i dont see any change.What i
have
> to do to modify the menu and where to place the code.The code snippet is
> int count;
>         char temp[13];
>         CMenu *pMenu = new CMenu();
>         CMenu *sMenu = new CMenu();

>         if(pMenu->LoadMenu(IDR_IETYPE))
>                 pMenu = pMenu->GetSubMenu(3);
>         count = pMenu->GetMenuItemCount();
>         wsprintf(temp,"%d",count);
>         MessageBox(temp);
>         if(pMenu)
>         {
>                 pMenu->AppendMenu(MF_STRING|MF_ENABLED,ID_MENU,"Naveen");
>                 MessageBox("Menu Appended");
>         }
>         count = pMenu->GetMenuItemCount();
>         wsprintf(temp,"%d",count);
>         MessageBox(temp);
>         DrawMenuBar();
>         pMenu->DestroyMenu();



Thu, 03 Nov 2005 17:46:42 GMT  
 Dynamic Menu Creation in MDI App
Look on: MVP VC++ FAQ: http://www.mvps.org/vcfaq/mfc/3.htm

--------------------

Quote:


>Subject: Re: Dynamic Menu Creation in MDI App
>Date: Fri, 16 May 2003 10:15:07 -0700
>Lines: 42
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

>Newsgroups: microsoft.public.vc.mfc,microsoft.public.vc.mfc.docview
>NNTP-Posting-Host: adeskout.autodesk.com 198.102.112.18
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.vc.mfc.docview:20843 microsoft.public.vc.mfc:375072
>X-Tomcat-NG: microsoft.public.vc.mfc.docview

>You have to modify the menu of the corresponding doctemplate. This menu
>handle is a public member of CMultiDoctemplate(m_hMenuShared).

>--
>Ajay Kalra [MVP - VC++]



>> Hello Netlanders,
>> I have to dynamically create a menu for my MDI App.When i use GetMenu() on
>> the OnCreate() handler in the CMainFrame class it gets the mainframe menu
>> i.e IDR_MAINFRAME.I want to modify the IDR_<appname>TYPE menu.If i modify
>it
>> using LoadMenu() in the OnCreate() Handler i dont see any change.What i
>have
>> to do to modify the menu and where to place the code.The code snippet is
>> int count;
>>         char temp[13];
>>         CMenu *pMenu = new CMenu();
>>         CMenu *sMenu = new CMenu();

>>         if(pMenu->LoadMenu(IDR_IETYPE))
>>                 pMenu = pMenu->GetSubMenu(3);
>>         count = pMenu->GetMenuItemCount();
>>         wsprintf(temp,"%d",count);
>>         MessageBox(temp);
>>         if(pMenu)
>>         {
>>                 pMenu->AppendMenu(MF_STRING|MF_ENABLED,ID_MENU,"Naveen");
>>                 MessageBox("Menu Appended");
>>         }
>>         count = pMenu->GetMenuItemCount();
>>         wsprintf(temp,"%d",count);
>>         MessageBox(temp);
>>         DrawMenuBar();
>>         pMenu->DestroyMenu();

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm



Mon, 07 Nov 2005 01:31:22 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Dynamic Menu Creation in MDI App

2. dynamic document creation in MDI app

3. Dynamic menu creation.

4. Dynamic Menu Creation

5. Adding menu items to an MDI app menu?

6. Prevent creation of default-view in MDI-apps?

7. How to remove dynamic menu item in MDI?

8. Event Handler for Dynamic Menu in MDI

9. Dynamic Menus in MDI program

10. Menu Resource Mgmt in MDI App With Many Views

11. Owner drawn menu in MDI app

12. Switching Menus in MDI App

 

 
Powered by phpBB® Forum Software