MFC Right-click popup menu and add response function

Source: Internet
Author: User

Problems encountered:

Add a right-click popup menu and add a response function, click the menu item but go into the unresponsive function.

Implementation steps:
1, create a new menu resource, Idr_tool_menu.

2, in the ClassWizard

void Cdlgtool::onrbuttonup (UINT nflags, CPoint Point)
{

CMenu menu; Define the CMenu object to be used below
Menu. LoadMenu (Idr_tool_menu); Loading a custom right-click menu
CMenu *ppopup = menu. GetSubMenu (0); Gets the first popup menu, so the first menu must have a submenu


CPoint point1;//defines a position to determine the position of the cursor
GetCursorPos (&point1);//Gets the position of the current cursor so that the menu can follow the cursor

Ppopup->trackpopupmenu (tpm_leftalign| Tpm_rightbutton,point1.x,point1.y,getparent ());//Display pop-up menu at specified location

Cdialog::onrbuttondown (nflags, point1);
}
At this point, when you right-click on the dialog, you can put the dishes out of the monotony, followed by the addition of response functions.


3. Right-click the menu item in the Resource View and select Add event handler.


4. Create a Class wizard for each item in the menu in the Resource View and add the command response function, and then include the statement in the function.

On_command (Id_tool_del, &cdlgtool::ontooldel)/

void Cdlgtool::ontooldel ()
{

AfxMessageBox ("success. ");
}


Problem found:

In step two above,

Ppopup->trackpopupmenu (tpm_leftalign| Tpm_rightbutton,point1.x,point1.y,this);

This means that the message of the Click menu is passed to this dialog box, and the corresponding change of its value can also be passed to other objects. such as GetParent (), is passed to the parent dialog box.


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.