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

You need to override the CExtPopupMenuWnd::g_nMsgPrepareMenu registered message in the frame window so that you can modify menus. This message is generated each time before any pop-up menu appears on the screen. Please add this line to the message map of the frame:

ON_REGISTERED_MESSAGE
   ( 
   CExtPopupMenuWnd::g_nMsgPrepareMenu,
   OnExtMenuPrepare
   )

Then, add this method to your frame window:

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 );
 
  // HERE IS YOUR CODE 
  // TO MODIFY pPopup (insert or remove anything)   
 
}

You may add some commands to the menu in resources so that these commands can be replaced with other commands in the CMainFrame::OnExtMenuPrepare() method. If you don't need to replace these commands, you may simply remove them.

For example, if we added an ID_MY_REPLACE_CMD command to the File menu, you can use the following code in the CMainFrame::OnExtMenuPrepare() method:

INT nReplacePos = pPopup->ItemFindPosForCmdID(ID_MY_REPLACE_CMD);
 
if(  nReplacePos >= 0 )
 
{
 
   // USER SHOULD NOT SEE THIS COMMAND
 
   VERIFY( pPopup->ItemRemove(nReplacePos) );
 
   // YOU ALSO MAY INSERT SOME COMMANDS TO THIS POSITION
 
   VERIFY( pPopup->ItemInsert( 
       (UINT)CExtPopupMenuWnd::TYPE_SEPARATOR, nReplacePos) 
   );
 
   VERIFY( pPopup->ItemInsert( ID_SOME_COMMAND, nReplacePos) );
 
}

Please note that all the commands should be registered in the command manager. The DRAWCLI sample carefully uses this technique to handle OLE menus and insert pop-up submenus for handling colors.