I have a Menu with all kinds of menu items, as usual. Each MenuItem element (button) has a title, and I would like to change that title at runtime. On a regular button, which is actually not a problem, I just call GetDlgItem(ID)->SetWindowText(CString);
However, I cannot do this in the menu items, since I cannot assign an identifier to any of them. The ID field in the property editor actually says "ID cannot be edited."
So, how do I change the text of menu items at runtime?
EDIT . I tried using CMenu :: ModifyMenu, however I was unsuccessful. I do not know how to specify the button (element) to change. In addition, I have doubts about the correctness of how I pass CString as an argument.
This is my unsuccessful attempt:
CString str = "Foo"; CMenu * pMenu = m_wndToolBar.GetMenu(); pMenu->ModifyMenu(1, MF_BYPOSITION | MF_STRING, 0 , str);
This (calling the ModifyMenu method) throws a debug assertion error. Please, not that I do not know what nIDNewItem is.
user-interface mfc visual-studio-2003 menuitem menu
David Božjak
source share