-
Change menu in view
Hello ,
I tried to change menu in view but it fail
I want to change menu in view
///
void CMainFrame::ChangMenu()
{
CMenu* mOld;
CMenu* mNew;
mOld = GetMenu();
if (mOld->DestroyMenu())
AfxMessageBox("Destroyed");
if (mNew->LoadMenu(IDR_MENU1))
AfxMessageBox("Loaded");
SetMenu(mNew);
}
-
Re: Change menu in view
Hi,
You did all exacly, but You know There is a small limitation in MFC's menus -> = "Your menu MUST hav at least 2 Main Popup menu Items........"
and thats all.
-
Re: Change menu in view
Hi ;
I tried 2 or more pop up but it doesn't work it fail in
LoadMenu member function
thanks
-
Re: Change menu in view
accordind to code shown above, you've got a error ----->> CMenu* mNew; ???(it's just a pointer not an object) so calling ---->> if (mNew->LoadMenu(IDR_MENU1)) will fail with no doubt.......
Good luck.
Do not ......... never mind
-
Re: Change menu in view
The new menu should be loaded using a CMenu instance, not a CMenu pointer that hasn't been initialised. When the new menu has been set, detach it from the CMenu object, or it will be destroyed when the CMenu goes out of scope at the end of your function.
void CMainFrame::ChangeMenu()
{
CMenu* mOld;
CMenu mNew;
mOld = GetMenu();
if (mOld->DestroyMenu())
AfxMessageBox("Destroyed");
if (mNew.LoadMenu(IDR_MENU1))
{
AfxMessageBox("Loaded");
SetMenu(&mNew);
mNew.Detach();
}
}
Dave
-
Re: Change menu in view
I am surprised that you do not have some kind of assertion or exception raised.
You are declaring two pointers with the storage class CMenu, but you do not have any CMenu object created!
You have to create object first, and then use LoadMenu:
CMenu* pOldMenu = GetMenu();
CMenu MenuNew;
MenuNew.LoadMenu(IDR_FORMTYPE1);
// pOldMenu->DestroyMenu();
SetMenu(&m_MenuNew);
and there is nothing Advanced about this.
Good Luck,
[email protected]
-
Re: Change menu in view
Correction.
I was trying to use member variable in my test code, that is why you have MenuNew and m_ MenuNew.
Code you should implement is as follow:
CMenu* pOldMenu = GetMenu();
CMenu MenuNew;
MenuNew.LoadMenu(IDR_FORMTYPE1);
// pOldMenu->DestroyMenu();
SetMenu(&MenuNew);
Sorry for mistake, but I was in a hurry.