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.