Method 1:
First locate the OnInitDialog () function in the Display menu Bar dialog box and add the following code to its function body:
CMenu menu;
Menu. LOADMENUW (idr_menu1);//Load the Resource menu bar, idr_menu1 the ID of the menu in the resource view
This->setmenu (&menu); This function sets the current menu to the specified menu.
It causes the window to be redrawn to reflect the change in the menu. The argument must be of the pointer type.
Menu. Detach ();//window is destroyed, local variable menu is destroyed at the same time
Method 2:
There is a menu drop-down list in the General column of the dialog box's property bar, choose IDR_MENU1 as the ID of the menus in the resource view, and run the program.
Another method of attachment
Method 3: Self-built popup dialog box
CMenu menu;
Menu. CreatePopupMenu ();
CPoint pt;
GetCursorPos (&PT);
Menu. AppendMenu (mf_bycommand| mf_enabled,201410, (LPCTSTR) "Direct processing");
Menu. AppendMenu (mf_bycommand| mf_enabled,201411, (LPCTSTR) "Direct send");
Menu. AppendMenu (mf_bycommand| mf_enabled,201412, (LPCTSTR) "Select Send");
int nid= (int) menu. TrackPopupMenu (Tpm_leftalign | Tpm_rightbutton | Tpm_returncmd, pt.x-14, pt.y+11, this);
Switch (NID)
{
Case 201410:
{
Break
}
Case 201411:
{
Break
}
Case 201412:
{
Cevenselsenddlg Dlg;
Dlg. DoModal ();
Break
}
Default
Break
}
Menu. DestroyMenu ();
MFC menu resource ID loaded onto the dialog box