Click to See Complete Forum and Search --> : Modify menuitems


Quakey
June 2nd, 1999, 02:39 PM
Hi there,
I wanted to modify the string of many menuitems on the fly. Here are the codes I used:
CMenu* hMenuCopy;
hMenuCopy=new CMenu;
hMenuCopy->LoadMenu(IDR_MENU_Display);
hMenuCopy->GetSubMenu(0)->GetSubMenu(7)->ModifyMenu(1,MF_STRING|MF_BYPOSITION,hMenuCopy->GetSubMenu(0)->GetSubMenu(7)->GetMenuItemID(1),Field1);

However, it doesn't work. Please tell me what's wrong. By the way, if I obtain the menu by using
GetMenu() rather than LoadMenu, those codes work. Why? Thanks in advance.

David Langis
June 2nd, 1999, 06:17 PM
You are modifying the new menu fine, which doesn't mean that it is the displayed menu. Why don't you want to use GetMenu() ?

Anyway, if you want to replace the current menu with the one you modified, do like the following.

// First destroy the current menu
GetMenu()->DestroyMenu();

// Then set the current menu
SetMenu(newMenu);

Quakey
June 5th, 1999, 01:07 PM
Hi there,
Thanks for the answer, however, I guess I didn't state my question clearly.

The menu I wanted to modify isn't the mainframe menu. It's already created in the resource, and I call
them up by using LoadMenu and then call TrackPopupMenu when the user right-click the mouse. I
needed to modify the menuitem in that menu at startup of the program with the codes in my previous
message, and it didn't work. So my question should be: is the menu in the resource changed when I
attemp to modify it or I just can't modify it permanently so that's why even though I've modified the
items but then I load it it just loads the original one from the resouce? If that's case, does that mean I
should modify the menu just before the call to TrackPopupMenu? Thanks.

David Langis
June 5th, 1999, 10:04 PM
ModifyMenu modifies an item in a menu whatever it is loaded from a resource or created at runtime. It does not change the resource. I don,t know if there is a way to modify a resource at runtime.