Modifying menu items

末鹿安然 提交于 2020-01-24 22:42:33

问题


I have a popup menu I would like to modify before it is being displayed. I can actually modify the string of a menu item fine. The problem is, that this renders it useless as nothing happens when the modified menu item is clicked on.

CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);

CWnd* pWndPopupOwner = this;
while(pWndPopupOwner->GetStyle() & WS_CHILD)
    pWndPopupOwner = pWndPopupOwner->GetParent();

// modify string
pPopup->ModifyMenu(1, MF_BYPOSITION | MF_STRING, NULL, oss.str().c_str());

pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner);

回答1:


Your call to ModifyMenu is setting the menu's ID to zero (via the third argument). You need to keep that ID the same.

If that's awkward, the SetMenuItemInfo API lets you change the string without changing the ID.



来源:https://stackoverflow.com/questions/14796341/modifying-menu-items

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!