Professional UI Solutions
Site Map   /  Register


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 » popup menu Collapse All
Subject Author Date
Tapasendra Datta Jul 24, 2007 - 12:24 AM

I want to disable the items of a popup menu.

Tapasendra Datta Jul 24, 2007 - 7:14 AM

but this code is not working, so can u give me the perfect code to disable a menuitem
mycode :
CMenu aMenu;
    CMenu *pPopUpMenu = aMenu.GetSubMenu(0);
    /*AfxGetMainWnd()->OnCmdMsg(state.m_nID, CN_UPDATE_COMMAND_UI, &state, NULL);
    AfxGetMainWnd()->OnCmdMsg(nid,ID_CUT_COPY,FALSE,NULL);    */

Technical Support Jul 24, 2007 - 8:53 AM

To disable the entire popup menu, you should handle the CExtPopupMenuWnd::g_nMsgPrepareOneMenuLevel registered message. For example, here is the code that disables the Toolbars sub menu.

LRESULT CMainFrame::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam)
    CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
        < CExtPopupMenuWnd::MsgPrepareMenuData_t * >
        ( wParam );
    ASSERT( pData != NULL );
    CExtPopupMenuWnd * pPopup = pData->m_pPopup;
    ASSERT( pPopup != NULL );
    INT nItemPos = pPopup->ItemFindByText( _T("&Toolbars") );
    if( nItemPos > 0 )
        CExtPopupMenuWnd::MENUITEMDATA & _mii = pPopup->ItemGetInfo( nItemPos );
        if( _mii.IsPopup() )
            _mii.SetForcePopupDisabled( true );

    return 1L;

Suhai Gyorgy Jul 24, 2007 - 8:15 AM

I can’t see any Prof-UIS related code, but here’s a possible solution, after all:

pPopUpMenu->TrackPopupMenu method shows your menu on the screen, so pPopUpMenu->RemoveMenu and pPopUpMenu->EnableMenuItem calls are just called after the popup menu has been closed. You should put pPopUpMenu->TrackPopupMenu line at the very end of this code snippet.

If that still doesn’t get your command disabled, you should go for the MFC command updating mechanism:
1. insert a line in your class’s message map:
2. add the following method for your class:
2.a) in .h:
afx_msg void OnUpdateYourCommand(CCmdUI* pCmdUI);
2.b) in .cpp:
void CYourClass::OnUpdateYourCommand(CCmdUI* pCmdUI)

Suhai Gyorgy Jul 24, 2007 - 5:13 AM

Check out this forum thread: CExtPopupMenuWnd::ItemEnabledSet
Support’s answer to this question should help you, too.