|
|
|
|
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.
Subject |
Author |
Date |
|
Moby Dick
|
Dec 14, 2004 - 3:45 AM
|
Hello all, Can you tell me how to dynamically modify a sub menu? Example: How to add C sub menus to a menu like: POPUP A BEGIN POPUP B BEGIN MENUITEM C1 MENUITEM C2 I did it like this: CMenu* _MainMenu = m_wndMenuBar.GetMenu(); int iPosMenu = FindMenuItem(_MainMenu, "&Menu1"); CMenu* _Menu2 = _MainMenu->GetSubMenu(iPosMenu); iPosMenu = FindMenuItem(_Menu2, "Menu&2"); _Menu3 = _Menu2->GetSubMenu(iPosMenu); iPosMenu = FindMenuItemEx(_Menu3, ID_ITEMSEARCHED); _Menu3->RemoveMenu(iPosMenu, MF_BYPOSITION); _Menu3->InsertMenu(ID_ITEMSEARCHED, MF_BYCOMMAND, ID_ITEMSEARCHED, "Some text"); VERIFY(g_CmdManager->UpdateFromMenu(pApp->m_pszProfileName, *_MainMenu)); But I would prefer to use your classes to be able to specify the values m_sMenuText, m_sToolbarText and m_sTipTool. Thanks a lot.
|
|
Technical Support
|
Dec 14, 2004 - 7:28 AM
|
The popup menus in Prof-UIS are not the same as Windows menus, they are coded from scratch. You can work with them like with CMenu or HMENU . You should not use the m_wndMenuBar.GetMenu code because it returns a temporary menu (for internal use only). To initialize any Prof-UIS menu (in the menu bar or toolbar or as a context menu), handle the CExtPopupMenuWnd::g_nMsgPrepareMenu registered windows message. This message is sent by entire popup menu tree each time when it is about to appear on the screen. Please use the following code:afx_msg LRESULT OnExtMenuPrepare(WPARAM wParam, LPARAM lParam);
ON_REGISTERED_MESSAGE(
CExtPopupMenuWnd::g_nMsgPrepareMenu,
OnExtMenuPrepare
)
LRESULT CMainFrame::OnExtMenuPrepare(WPARAM wParam,
LPARAM lParam)
{
CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
reinterpret_cast
< CExtPopupMenuWnd::MsgPrepareMenuData_t * >
( wParam );
ASSERT( pData != NULL );
CExtPopupMenuWnd * pPopup = pData->m_pPopup;
ASSERT( pPopup != NULL );
// put your pPopup menu modification here
}
Please take a look at the DRAWCLI sample application to see how this mechanism works.
|
|
Moby Dick
|
Dec 20, 2004 - 4:44 AM
|
Hello all ! I’m sorry but this will not run properly. Perhaps I’ve got other error(s) in my code ? Please take a look at my source (extract from CMainFrame::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam)): // Popup-menu creation for year selection. // INT nReplacePos = pPopup->ItemFindPosForCmdID(ID_CURRYEAR); if (nReplacePos >= 0) { CExtPopupMenuWnd* pYearPopup = new CExtPopupMenuWnd; VERIFY(pYearPopup->ItemInsert(ID_CURRYEAR_1, 0, "2004", 0)); VERIFY(pPopup->ItemInsertSpecPopup(pYearPopup, nReplacePos + 1, pPopup->ItemGetText(nReplacePos), pPopup->ItemGetIcon(nReplacePos))); pPopup->ItemSetDisplayed( nReplacePos + 1, true ); VERIFY( pPopup->ItemRemove(nReplacePos) ); } // if( nReplacePos >= 0 ) return 1; There is no error on execution, but the sub menu is empty (a white square is shown). Can you help me ? Thanks a lot.
|
|
Moby Dick
|
Dec 20, 2004 - 5:41 AM
|
Sorry... I think it’s a stupid question !!! My error will come from the "pPopup->ItemGetText(nReplacePos)". It must be: "pPopup->ItemGetText(nReplacePos + 1)"... No ?
|
|