1、新建一MFC的对话框应用程序;
2、在资源里面新建一菜单IDR_MENU2作为弹出的右键菜单;
3、添加一ListCtrl控件,并在OnInitDialog函数中为其初始化数据;
4、添加WM_CONTEXTMENU消息;并在该消息的响应函数中添加如下代码:
CMenu m_popupmenu;
m_popupmenu.LoadMenu(IDR_MENU2);
CMenu* pPopupMenu;
pPopupMenu = m_popupmenu.GetSubMenu(0);
pPopupMenu->TrackPopupMenu(TPM_LEFTBUTTON|TPM_LEFTALIGN,point.x,point.y,this);
m_popupmenu.DestroyMenu();