Reputation: 203
For many language, I must dynamic change POPUP Text of Menu,
but it is no ID to control this text, as follow code reference resource
IDR_MENU_MAIN MENU
BEGIN
POPUP "File(&F)" // I want to change this
BEGIN
MENUITEM "Open(&O)", ID_CURVE_FILE_NEW
MENUITEM SEPARATOR
MENUITEM "Recent File", ID_FILE_MRU_FILE1, GRAYED
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_APP_EXIT
END
POPUP "Language(&L)" // I want to change this
BEGIN
MENUITEM "Traditional Chinese", ID_LANGUAGE_CHT
MENUITEM "Simplified Chinese", ID_LANGUAGE_CHS
MENUITEM "English", ID_LANGUAGE_ENG
MENUITEM "Russian", ID_LANGUAGE_RUS
MENUITEM "Korean", ID_LANGUAGE_KOR
MENUITEM "Japanese", ID_LANGUAGE_JPN
END
POPUP "Help(&H)" // I want to change this
BEGIN
MENUITEM "", ID_APP_ABOUT
END
END
thanks all!
Upvotes: 1
Views: 1951
Reputation: 203
I response my question, change the code
CMenu* pMenu = CMenu::FromHandle(hMenu);
to
CMenu* pMenu = GetMenu();
It will work! thanks a lot!
Upvotes: 2
Reputation: 5132
Following is some code to TRACE
and modify the popup-menu strings (hMenu
is the handle to the main menu); if your application uses the "new style" menu bar CMFCMenuBar
, you will need to call m_wndMenuBar.GetHMenu()
and m_wndMenuBar.CreateFromMenu(hMenu, TRUE, TRUE);
before and afterwards respectively:
CMenu* pMenu = CMenu::FromHandle(hMenu);
int i, nCou = pMenu->GetMenuItemCount();
UINT uID;
CString ss;
for (i = 0; i < nCou; i++)
{ uID = pMenu->GetMenuItemID(i);
if (uID == 0) // separator
{ TRACE(_T("----------------------\n"));
continue;
}
pMenu->GetMenuString(i, ss, MF_BYPOSITION);
if (uID == (UINT)-1)
{ TRACE(_T("Popup '%s' "), ss);
ss += _T("-Modified");
pMenu->ModifyMenu(i, MF_BYPOSITION, 0, ss);
TRACE(_T("modified to '%s' "), ss);
}
else
TRACE(_T("Item '%s', ID=%d "), ss, uID);
TRACE(_T("\n"));
}
Upvotes: 2
Reputation: 199
It's tricky.
What I have done is to have an enumeration that matches the top-level elements of the menubar and then reference them by position.
Then instead of using MF_BYCOMMAND to update them you must use MF_BYPOSITION.
Upvotes: 0
Reputation:
Try to use 'setlocale'.
For example:
setlocale( LC_ALL, "Traditional Chinese" );
setlocale( LC_ALL, "Simplified Chinese" );
..
..
http://msdn.microsoft.com/en-us/library/x99tb11d(v=vs.90).aspx
Upvotes: 0