CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    117

    Modify menuitems

    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.


  2. #2
    Join Date
    May 1999
    Posts
    44

    Re: Modify menuitems

    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);


  3. #3
    Join Date
    Apr 1999
    Posts
    117

    Re: Modify menuitems

    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.


  4. #4
    Join Date
    May 1999
    Posts
    44

    Re: Modify menuitems

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured