MFC Right-click popup menu

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.