Pop-up - worked example
key : purple - original code / blue - new code
Step 1 :
Continue with the program names.
Step 2 :
Add a Pop-up menu to the resources. Give this a sensible ID (IDR_POP_UP_MENU). Link the three options (Remove, Remove All and Edit) to their respective functions :
Step 3 :
Add the OnRButtonDown() handler to the ListCtrl class. Add the following code to this :
void
CNameListView::OnRButtonDown(UINT nFlags, CPoint point)
{
CListView::OnRButtonDown(nFlags, point);
CMenu popup;
ClientToScreen(&point);
popup.LoadMenu(IDR_POP_UP_MENU);
CMenu* pMenu = popup.GetSubMenu(0);
ASSERT(pMenu);
pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,
point.x, point.y, this);
}
Click here for the basic exercise
Click here for the source code
Click here to return to menu