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 » Change menu at runtime Collapse All
Subject Author Date
jb lee Feb 27, 2006 - 1:02 AM

Can I change main menu at runtime?
The scenario is :-
I have three main menus : ID_MENU_1, ID_MENU_2, and ID_MENU_3
Three menus has menu item for current menu selection.
When a menu is selected, toolbar and some windows should reflect the change.

Do I have to regist all IDs to the statBasicCommands[] ?
Best regards,

jb.

ps, Search result page of prof-uis forum return error when I select other page.

Technical Support Feb 28, 2006 - 3:12 AM

If you need to change only popup menu items, simply handle the CExtPopupMenuWnd::g_nMsgPrepareMenu registered windows message in your main frame window:

afx_msg LRESULT OnExtMenuPrepare(WPARAM wParam, LPARAM lParam);
    ON_REGISTERED_MESSAGE(
        CExtPopupMenuWnd::g_nMsgPrepareMenu,
        OnExtMenuPrepare
        )
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 );
    // MODIFY pPopup MENU HERE
 
    return 1;
}
You can insert some items with pre-defined command identifiers into your menu resource. This will allow the CMainFrame::OnExtMenuPrepare() method to find them and replace with other needed menu items:
INT nItemPos = pPopup->ItemFindPosForCmdID( ID_WELL_KNOWN_MENU_ITEM );
    if( nItemPos > 0 )
    {
        pPopup->ItemRemove( nItemPos );
        pPopup->ItemInsert( . . . );
        . . .
    }
It is also possible to rebuild the top level of the menu bar. The menu bar (CExtMenuControlBar) is based on a toolbar (CExtToolControlBar). The CExtMenuControlBar::UpdateMenuBar() method invokes an algorithm that rebuilds the menu bar’s toolbar buttons. You can implement your own algorithm of filling the menu bar with buttons (CExtBarButton). Create your own CExtMenuControlBar-derived class and override the CExtMenuControlBar::_UpdateMenuBar() internal virtual method. Your method can be either based on the original method (you only embed needed buttons) or completely rebuild an array of buttons in your own manner. All the commands inside the menus attached to the menu bar buttons should be registered in the command manager. The top level buttons in the menu bar also have their unique command identifiers and should be allocated exactly like it is done in the CExtMenuControlBar::_UpdateMenuBar() method.

We fixed the search feature available in our forums, thank you for the bug report.