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();



Mon, 31 Oct 2005 18: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 08: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();



Tue, 01 Nov 2005 18: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 10:46:42 GMT  
 
 [ 4 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