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

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


    }


  2. #2
    Guest

    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.



  3. #3
    Join Date
    Apr 1999
    Posts
    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


  4. #4
    Join Date
    Apr 1999
    Posts
    10

    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

  5. #5
    Join Date
    Apr 1999
    Posts
    383

    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


  6. #6
    Guest

    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]


  7. #7
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    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
  •  





Click Here to Expand Forum to Full Width

Featured