The use of the "MFC" Mfcmenubutton

Source: Internet
Author: User

Background: Because of the limited space on the dialog, I decided to use a Mfcmenubutton to implement the same class of button events in order to save space. Originally I intended to set two buttons: "Single delete Files" and "Empty All Files" two buttons, but the space is too small, and the functions of the two buttons are similar, so I simply combine the two buttons into a button, using the drop-down menu to select the way to trigger the button event respectively.

First, you need to create a menu resource. If there is no menu folder in the Resource view, you need to right-click the folder with the suffix. RC in the Resource View window and select Add resource to pop up the dialog box.

In the popup dialog box, select Menu, then click the New button. Set the name of each option on the drop-down menu above the newly created menu.

The IDs for each of the two options are set as shown below.

OK, now this is called "idr_menu1" the menu is edited, the following in the Mfcmenubutton call the menu resource.

First, you need to create a new Mfcmenubutton control, and then add the associated variable, assuming m_menubutton1.

Insert the following code into the OnInitDialog () function of the dialog box to load the menu resource.

1 New CMenu; 2 // Loading Menu Resources 3 m_menubutton1.m_hmenu = Pmenu->getsubmenu (0)->getsafehmenu ();

Insert the following code in the button event to test.

 void   ctabpage2::o NBnClickedMfcmenubuttonDelete1 () { //  TODO: Add control notification handler code here  if  (m_menubutton1.m_nmenuresult == Id_x_single) {AfxMessageBox (_t ( "   single delete file!      "  else  if  (m_menubutton1.m_ Nmenuresult == Id_x_all) {AfxMessageBox (_t (  "
      delete all files   "     return  ;}  

The part of the popup dialog can be replaced with a function statement to perform different functions separately.

The use of the "MFC" Mfcmenubutton

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.