Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Modifying CExtMenuControlBar dynamically. Collapse All
Subject Author Date
a a Jan 25, 2006 - 9:48 PM

I’m using CExtMenuControlBar for the main frame’s menu bar, in an MDI application.
How do you dynamically change the content of the menu bar?


I tried using:
menubar.GetMenu()->{Append,Modify,Insert}Menu(...);
and EnableMenuItem on it, but it didn’t work.


In fact, I’d like to set a different menu when a CExtControlBar-derived has the focus,
like if the control bar was a childview (but I want it to be docked). So I tried something like this in the beginning:
CMenu *m = new CMenu();
m->LoadMenu(IDR_MENU_RESOURCETREE);
menubar.SetMenu(m);
but it didn’t work.


Is there a way to change the menu of the menubar?
Otherwise, is there a way to make a submenu enabled/disabled, to work around?


Thanks, and sorry for posting so many threads...

Technical Support Jan 26, 2006 - 12:49 PM

The CExtMenuControlBar::UpdateMenuBar() method makes the menu bar rebuild its buttons. Building the content of menu bar is performed in the CExtMenuControlBar::_UpdateMenuBar() internal virtual method which you can override in your CExtMenuControlBar-derived class. Your method should be similar to the original but simply use the custom menu for building the array of buttons. This approach allows you to control the content of the menu bar depending on the focused window(s).

a a Jan 26, 2006 - 7:36 PM

Thanks. It... works.


Code excerpt:


  BOOL Menu::_UpdateMenuBar(BOOL bDoRecalcLayout)
  {
    SetButtons(); // remove all buttons


    // ...


    if( pMenuInfo != NULL )
    {
      ASSERT_VALID( pMenuInfo->GetNode() );
      SetButtons( pMenuInfo->GetNode() );
    } // if( pMenuInfo != NULL )
    else
    {

      CMenu * pMenu;
      if (_menu_content != NULL) // Use a customized menu if _menu_content points to a CMenu
        pMenu = _menu_content;
      else
        pMenu = GetMenu();
      if( pMenu != NULL && pMenu->GetSafeHmenu() != NULL )
      {
        ASSERT( ::IsMenu(pMenu->GetSafeHmenu()) );


    // ...


    if( bDoRecalcLayout )
    {
      Invalidate();
      _RecalcLayoutImpl();
      UpdateWindow();
      if( m_pDockSite != NULL )
      {
        CFrameWnd * pFrame = GetParentFrame();
        ASSERT_VALID( pFrame );
        //if( pFrame->IsKindOf(RUNTIME_CLASS(CExtMiniDockFrameWnd)) )      // Couldn’t find CExtMiniDockFrameWnd’s header... Oh well...
        //  pFrame->SetWindowPos(
        //  NULL, 0, 0, 0, 0,
        //  SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE
        //  |SWP_NOZORDER|SWP_NOOWNERZORDER
        //  |SWP_FRAMECHANGED
        //  );
      } // if( m_pDockSite != NULL )
    } // if( bDoRecalcLayout )
    return TRUE;
  }

Technical Support Jan 27, 2006 - 10:50 AM

Your code is correct.