How to dynamically modify menu in MDI app
-
Hello everybody! I´m writing a MDI app. Application Wizard generates two menus: One (IDR_MAINFRAME), which is displayed when no document is open, the other (IDR_XXXTYPE) when there is at least one document opened. This code below (from CMainFrame::OnCreate) modifies the first menu. I want to do the same modification to the other menu. How to do that? Thank you for any comments. Jerzy CMenu PopupMenu; PopupMenu.CreateMenu(); for(int i=0;i<3;i++) { CString str; str.Format("Item %d",i); PopupMenu.AppendMenu(MF_STRING,IDM_ITEM+i,str) ; } CMenu *m=GetMenu(); m->AppendMenu(MF_POPUP¦MF_STRING,(UINT)PopupMenu.m_hMenu,"&Items"); PopupMenu.Detach();
-
Hello everybody! I´m writing a MDI app. Application Wizard generates two menus: One (IDR_MAINFRAME), which is displayed when no document is open, the other (IDR_XXXTYPE) when there is at least one document opened. This code below (from CMainFrame::OnCreate) modifies the first menu. I want to do the same modification to the other menu. How to do that? Thank you for any comments. Jerzy CMenu PopupMenu; PopupMenu.CreateMenu(); for(int i=0;i<3;i++) { CString str; str.Format("Item %d",i); PopupMenu.AppendMenu(MF_STRING,IDM_ITEM+i,str) ; } CMenu *m=GetMenu(); m->AppendMenu(MF_POPUP¦MF_STRING,(UINT)PopupMenu.m_hMenu,"&Items"); PopupMenu.Detach();
Use GetSubMenu to get the proper menu and continue as you have been.
-
Use GetSubMenu to get the proper menu and continue as you have been.
Hi, I don't know what you mean to use GetSubMenu()? This code is working, it ataches a new popup to the main menu. The problem is that it ataches this submenu to the IDR_MAINFRAME menu (after main frame is created). I need to do the same for IDR_VIEWTYPE menu. I don't know in what moment that menu is created. If I use this code in that moment, the new popup would be attached to IDR_VIEWTYPE menu. Jerzy
-
Hi, I don't know what you mean to use GetSubMenu()? This code is working, it ataches a new popup to the main menu. The problem is that it ataches this submenu to the IDR_MAINFRAME menu (after main frame is created). I need to do the same for IDR_VIEWTYPE menu. I don't know in what moment that menu is created. If I use this code in that moment, the new popup would be attached to IDR_VIEWTYPE menu. Jerzy
The handle of the IDR_XXXTYPE menu is accessible through public data member of the CMultiDocTemplate class, it's called m_hMenuShared. Tomasz Sowinski -- http://www.shooltz.com
-
The handle of the IDR_XXXTYPE menu is accessible through public data member of the CMultiDocTemplate class, it's called m_hMenuShared. Tomasz Sowinski -- http://www.shooltz.com
Hi Tomek, Thanks for the solution. It works - it ataches a new popup to IDR_XXXTYPE menu. But the problem is that I don't know where this code should be placed. If I put it in OnCrete() of ChildFrm, then the new popup is atached as many times as ChildFrm frames were created. MSDN says something that this menu is loaded during the construction of the document templates. Can I override this? Thanks for any suggestions. Jerzy
-
Hi Tomek, Thanks for the solution. It works - it ataches a new popup to IDR_XXXTYPE menu. But the problem is that I don't know where this code should be placed. If I put it in OnCrete() of ChildFrm, then the new popup is atached as many times as ChildFrm frames were created. MSDN says something that this menu is loaded during the construction of the document templates. Can I override this? Thanks for any suggestions. Jerzy
You should add popups after creating new CMultiDocTempltate, in CYourApp::InitInstance. Tomasz Sowinski -- http://www.shooltz.com
-
You should add popups after creating new CMultiDocTempltate, in CYourApp::InitInstance. Tomasz Sowinski -- http://www.shooltz.com
Hi Tomek, Thank you very much for this tip. It works. I had to only call DrawMenuBar() to refresh the menu. Without this call the menu was updated only when the mouse was over the menu. (This is only when the application starts). When all documents were closed and then I opened a new one the menu was shown correctly. Dziekuje, Jerzy :)