CMenu popupMenu; popupMenu.CreatePopupMenu(); popupMenu.AppendMenu(MF_STRING, 1, "Option 1"); popupMenu.AppendMenu(MF_STRING, 2, "Option 2"); popupMenu.AppendMenu(MF_SEPARATOR); popupMenu.AppendMenu(MF_STRING, 3, "Option 3");
void MyWindow::OnContextMenu(CWnd* pWnd, CPoint point) { CMenu popupMenu; popupMenu.CreatePopupMenu(); popupMenu.AppendMenu(MF_STRING, 1, "Option 1"); popupMenu.AppendMenu(MF_STRING, 2, "Option 2"); popupMenu.AppendMenu(MF_SEPARATOR); popupMenu.AppendMenu(MF_STRING, 3, "Option 3"); popupMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this); }In this example, the CreatePopupMenu function is used to create a popup menu when the user right-clicks on a window. It adds the same three options and separator as in the previous example and then uses the TrackPopupMenu function to display the menu at the cursor location. The package library for CMenu CreatePopupMenu is the Microsoft Foundation Classes (MFC), which is part of the Visual C++ development environment.