You are getting state with ID, but popup menu don't have ID.
reback to the initial text. How can I avoid this?
Tks.
"Joseph M. Newcomer" wrote:
See below...
On Wed, 23 May 2007 10:57:01 -0700, Rui Oliveira <RuiOliveira@discussions.microsoft.com>
wrote:
I want modify the text in a popupmenu in my mainframe menus.
I have the following sample.
File
>New > Document
> File
>Open
>Exit
All items are easy to change text because they have an ID. To change ???File???
and ???Open???:
CMenu* lcl_menu = AfxGetMainWnd()->GetMenu();
****
Stop right here. This is where you are immediately going wrong. You will need to add an
OnInitMenuPopup handler, and update the menu at that point.
*****
lcl_menu->ModifyMenu( 0, MF_BYPOSITION, 0, ???FileX???);
*****
This is only safe it is SDI. If it is MDI, the menu will start at offset 1. Whenever you
are using MF_BYPOSITION, you must first compute the menu item you wish to modify and only
THEN can you modify it. Fortunately, this is already done for you.
void CMyClass::OnInitMenuPopup(CMenu * popup, UINT index, BOOL bSysMenu)
{
if(!bSysMenu)
{
UINT state = popup->GetMenuState(ID_FILE_OPEN);
if(state != (UINT)-1)
{
popup->ModifyMenu(index, MF_BYPOSITION, 0, _T("&FileX"));
AfxGetMainWnd()->DrawMenuBar();
}
}
CParentOfMyClass::OnInitMenuPopup(popup, index, bSysMenu);
*****
lcl_menu->ModifyMenu( ID_OPEN, MF_STRING, ID_OPEN, ???OpenX???
*****
This needs to be done elsewhere. Add an OnUpdateCommandUI handler:
void CMyClass::OnUpdateOpen(CCmdUI * pCmdUI)
{
pCmdUI->SetText(_T("&OpenX"));
}
Note that you should NOT hardwire these strings, but they should be loaded from the
STRINGTABLE, or you will have trouble localizing the app. Don't forget the _T() around
all the literal strings. 8-bit strings are rather quaint.
****
AfxGetMainWnd()->DrawMenuBar();
How can I change ???New????
****
The same was as shown for Open
****
Thanks.
Rui
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm