How to change popup menu item text in runtime?
By Yaroslav Goncharov, August 21, 2002.
Question
I want to change popup menu item text. I have read the Modifying Smartphone menu bars in runtime article,
but it does not work for me. I use the following code to change the item text.
TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_TEXT;
tbbi.pszText = _T("Stop");
::SendMessage (hMenuBar, TB_SETBUTTONINFO, IDM_ACTION_ITEM, (LPARAM)&tbbi);
What am I doing wrong?
Answer
Your code is designed for changing the text of a menu bar button (not a popup menu item). Have a look at the picture to see
the difference.
You can use the following steps to change text of a popup menu item:
- Obtain HMENU of the corresponding popup menu.
- Use standard menu API to change the popup menu.
Unfortunately, ModifyMenu API function is not supported under Windows CE. However, it is possible
to emulate this function using DeleteMenu and InsertMenu.
The following code snippet changes the text of a popup menu item.
// obtain handle of the corresponding popup menu
TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_LPARAM;
::SendMessage (m_hMenuBar, TB_GETBUTTONINFO, IDM_OPTIONS_MENU, (LPARAM)&tbbi);
HMENU hPopupMenu = (HMENU) tbbi.lParam;
// emulate ModifyMenu
::DeleteMenu(hPopupMenu, 0, MF_BYPOSITION);
::InsertMenu(hPopupMenu, 0, MF_BYPOSITION, IDM_MENU_ITEM_ACTION, _T("Play"));
Discuss
Discuss this QA.
Here you can write your comments and read comments of other developers.
|