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 General Discussion » Changing frame's main menu Collapse All
Subject Author Date
Mirco Alexis Feb 11, 2004 - 10:01 AM

Hello,


I’m sorry but I can’t change dynamically the main menu of a CFrameWnd.


I tried to update it (inserting/removing and changing items) thru the CExtMenuControlBar’s GetMenu() and UpdateMenuBar() functions, but the latter crashes.


Any help would be much appreciated.


Mirco

Technical Support Feb 12, 2004 - 8:58 AM

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.