Hi,
As usual I can write:
menu.LoadMenu(IDR_MENU1);
CMenu *pPopup = menu.GetSubMenu( 0 );
pPopup->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
this );
to show a context menu.
But I do not want that since I plan to use the same menu in different
contexts, showing different menu items. And I do not want to delete existing
menu items. I'd much rather add menu items actively!
So, I'd like to create a context menu dynamically, something like:
void CDynMenuView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu menu;
if (!menu.CreatePopupMenu())
return;
menu.InsertMenu(-1,MF_BYCOMMAND|MF_BYPOSITION,ID_POPUP_TEST);
menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
this );
}
However, this does not work...
I guess I use ID_POPUP_TEST incorrectly. I want to use ID_POPUP_TEST as a
commandid and menutext, hence defined it as:
IDR_MENU1 MENU DISCARDABLE
BEGIN
POPUP ""
BEGIN
MENUITEM "Test...", ID_POPUP_TEST
END
END
What is the correct way of creating this context menu dynamically?
/Tom