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