|
|
|
|
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 |
|
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; aMenu.LoadMenuW(IDR_MENU1); CMenu *pPopUpMenu = aMenu.GetSubMenu(0); pPopUpMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,this); //pPopUpMenu->CreateMenu(); //pPopUpMenu->EnableMenuItem(ID_CUT_COPY,MF_BYCOMMAND|MF_DISABLED); //AfxMessageBox("pPopUpMenu->GetMenuItemID(-1)",MB_OK); /*AfxGetMainWnd()->OnCmdMsg(state.m_nID, CN_UPDATE_COMMAND_UI, &state, NULL); AfxGetMainWnd()->OnCmdMsg(nid,ID_CUT_COPY,FALSE,NULL); */ pPopUpMenu->RemoveMenu(ID_POPUP_DELETE,TRUE); pPopUpMenu->EnableMenuItem(ID_POPUP_CUT,MF_BYCOMMAND|MF_DELETE);
|
|
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 =
reinterpret_cast
< 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:
ON_UPDATE_COMMAND_UI(ID_YOUR_COMMAND_TO_DISABLE, OnUpdateYourCommand) 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) { pCmdUI->Enable(FALSE); }
|
|
Suhai Gyorgy
|
Jul 24, 2007 - 5:13 AM
|
|
|