MFC menu resource ID loaded onto the dialog box

Source: Internet
Author: User

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

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.