Dear Mirco,
When you start a Prof-UIS application, the standard MFC menu is replaced with that of Prof-UIS (the latter, in fact, is not a menu, but rather its imitation). So, when invoking the CExtMenuControlBar::GetMenu()
method, you get a pointer to that MFC’s CMenu
, which is completely useless in your case. This returned CMenu
deals with the standard menu line which has been killed by the Prof-UIS menu bar and is only used for constructing popup items of the menu bar. You should not access, nor change this CMenu
. To change the text of any menu item on-the-fly, you just need to implement the corresponding command update handler and put pCmdUI->SetText()
to there.
Dynamic menu construction
If you need to modify the menu dynamically (inserting/removing menu items on-the-fly),
then you should handle the CExtPopupMenuWnd::g_nMsgPrepareMenu
registered windows message.
Please add the following method to your frame window:
afx_msg LRESULT OnExtMenuPrepare(WPARAM wParam, LPARAM lParam);
Add the macros belowto frame’s message map:
ON_REGISTERED_MESSAGE( CExtPopupMenuWnd::g_nMsgPrepareMenu, OnExtMenuPrepare)
Here is a sample implementation of the method:
LRESULT CMainFrame::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam)
{
lParam; // unused
CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
reinterpret_cast
< CExtPopupMenuWnd::MsgPrepareMenuData_t * > ( wParam );
ASSERT( pData != NULL );
CExtPopupMenuWnd * pPopup = pData->m_pPopup;
ASSERT( pPopup != NULL );
//
// !!! put the code responsible for modifying your pPopup menu here !!!
//
. . .
}
In your version of the
OnExtMenuPrepare()
method you can modify the
pPopup
menu object.
You can do this with the following methods of the
CPopupMenuWnd
class:
1)
ItemFindPosForCmdID
- Find an index of the command
2)
ItemRemove
- Remove a menu item with the specified index
3)
ItemInsert
- Insert a command or submenu
4)
ItemInsertSpecPopup
- Insert any kind of
CExtPopupMenuWnd
as a submenu (may be used for inserting color selection popups)
5)
ItemSetDisplayed
- Marks a menu item as initially displayed (i.e. not rarely used item)
These methods allow you to define some commands like MFC’s ID_MRU_FILE_FIRST for further replacing them with the other commands and/or with dynamically constructed submenus on-the-fly.