|
-
April 20th, 1999, 06:07 AM
#1
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);
}
-
April 20th, 1999, 07:37 AM
#2
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.
-
April 21st, 1999, 04:30 AM
#3
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
-
April 26th, 1999, 01:02 AM
#4
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
-
April 26th, 1999, 05:43 AM
#5
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
-
October 2nd, 1999, 04:00 PM
#6
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]
-
October 2nd, 1999, 07:21 PM
#7
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.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|