Click to See Complete Forum and Search --> : Change menu in view


Mido
April 20th, 1999, 06:07 AM
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);


}

April 20th, 1999, 07:37 AM
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.

Mido
April 21st, 1999, 04:30 AM
Hi ;
I tried 2 or more pop up but it doesn't work it fail in
LoadMenu member function
thanks

Lavrent
April 26th, 1999, 01:02 AM
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

Dave Lorde
April 26th, 1999, 05:43 AM
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

October 2nd, 1999, 04:00 PM
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,
JohnCz@snip.net

JohnCz
October 2nd, 1999, 07:21 PM
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.