How to dynamically update the contents of the menu activated from the drop-down button built in a toolbar/menu?

Professional User Interface Suite, Copyright FOSS Software Inc. Help Published with Permission.

There is a very simple method to create a toolbar button with a separated drop-down area (see Figure at the bottom) which is tracking the dynamically created menu.

1) Create a toolbar button with a drop-down menu and assign a menu (e.g., IDR_DYNAMIC_POPUP_MENU) to it. This menu should have a temporary menu item with a certain ID (e.g., ID_TEMP)

INT nBtnIdx = m_wndToolBar.CommandToIndex( ID_SOME_CMD );
ASSERT( nBtnIdx >= 0 );
CMenu _line_menu;
VERIFY( _line_menu.LoadMenu( IDR_DYNAMIC_POPUP_MENU ) );
VERIFY( m_wndToolBar.SetButtonMenu( 
    nBtnIdx, _line_menu.Detach() ) );
CExtBarButton * pTBB = 

2) The CExtPopupMenuWnd::g_nMsgPrepareMenu message is sent each time a menu is about to appear on the screen. So, just search for the temporary menu item with the specified ID in message handler, and, if it is found, just remove it and add any required item(s):

LRESULT CMainFrame::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam)
   CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
       CExtPopupMenuWnd::MsgPrepareMenuData_t *
     >( wParam );
   ASSERT( pData != NULL );
   CExtPopupMenuWnd * pPopup = pData->m_pPopup;
   ASSERT( pPopup != NULL );
   INT nItemPos = pPopup->ItemFindPosForCmdID( 
   if( nItemPos >= 0 )
    pPopup->ItemRemove( nItemPos );