The right-click Pop-up menu refers to the menu that pops up when the right button is lifted. Usually placed in the Onrbuttonup response function of dialog.
An example of a right-click popup menu is given below:
1 Adding right-click events and Response functions
You can use the class Wizard ... To add a right-click Message wm_rbuttonup and add handler to it, the onrbuttonup response function is generated automatically
2 adding a resource to a pop-up menu
You can add a new pop-up menu resource using "String Table" in "Resource View", which assumes the resource Id:idc_menu_update_point, Caption: Modify Point
3 Creating a popup menu
Create, display, eject, and destroy pop-up menus in onrbuttonup
void Cmfcdlg::onrbuttonup (UINT nflags, CPoint point) {//todo:add your message handler code here and/or call default CMenu m ENU ; //define Menu Object menu . CreatePopupMenu (); //create pop-up menu menu . AppendMenu (mf_string | Mf_enabled, Idc_menu_update_point, _t ( "Modify Point" )); //associate a popup menu with a resource CPoint pt; GetCursorPos (&PT); //gets the position of the current mouse to display the pop-up menu in this location menu . TrackPopupMenu (Tpm_rightbutton,pt.x,pt.y,this); //display pop-up menu menu . DestroyMenu (); //destroy pop-up menu Cdialogex::onrbuttonup (nflags, point);}
4 Add a popup menu response function
Add a new item in Message_map to allow the popup menu to respond to a custom function
ON_COMMAND(IDC_MENU_UPDATE_POINT, OnUpdatePoint)
5 Declaration and implementation of the popup menu response function Onupdatepoint
(1) header file
void OnUpdatePoint();
(2) Source file
void CmfcDlg::OnUpdatePoint(){ AfxMessageBox(_T("右键弹出菜单!"));}
MFC Right-click popup menu