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 Tech Support » Submenu question Collapse All
Subject Author Date
Gevork Odabashyan Nov 2, 2004 - 7:08 AM

Hello...


In the help topic "How to insert menu items at runtime?" You say that "CExtPopupMenuWnd::g_nMsgPrepareMenu registered message... is generated each time any popup menu appears on the screen". But in my humble opinion this message is generated only for top-level popup menus. It is not generated for submenus. How can I insert items in submenu at runtime?


Thank You, Ruslan.

Technical Support Nov 2, 2004 - 10:03 AM

You are absolutely right. The CExtPopupMenuWnd::g_nMsgPrepareMenu registered windows message is sent for the entire menu tree. This mean you need to implement some recursive function that will be called from the message handler. It should traverse the menu tree and modify any menu item on any sublevel if needed. The "... any popup menu appears ..." phrase implies the entire popup menu tree.

LRESULT CMainFrame::OnExtMenuPrepare(
 WPARAM wParam,
 LPARAM lParam
 )
{
 lParam; 
 CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
   reinterpret_cast 
   < CExtPopupMenuWnd::MsgPrepareMenuData_t * >
   ( wParam );
 ASSERT( pData != NULL );
 CExtPopupMenuWnd * pPopup =
  pData->m_pPopup;
 ASSERT( pPopup != NULL );
 if( _DoMyMenuPrepare( pPopup ) )
  pData->m_bMenuChanged = true;
}
LRESULT CMainFrame::_DoMyMenuPrepare(
 CExtPopupMenuWnd * pPopup
 )
{
 // method returns true if pPopup items were changed
 int nCount = pPopup->ItemGetCount();
 for( int i = 0; i < nCount; i++ )
 {
  MENUITEMDATA & _mii = ItemGetInfo( ItemGetCount()-1 );
  if( _mii.IsSeparator() )
   continue;
  if( _mii.IsPopup() )
  {
   CMainFrame::_DoMyMenuPrepare(
    _mii.GetPopup()
    );
   continue;
  }
// HERE IS:
// please insert your initialization code for the pPopup
// sublevel’s commands
 }
}

Gevork Odabashyan Nov 3, 2004 - 5:35 AM

Ambiguity disapeared. Thank You!