How to dynamically add and delete the Insert menu (by tapping the code)
Cmenu menu;
Menu. createpopupmenu ();
// Getmenu ()-> appendmenu (mf_popup, (uint) menu. m_hmenu, "Fuck ");
// Menu. insertmenu (2, mf_byposition, (uint) menu. m_hmenu, "you"); // This call is incorrect. You must use a menu handle to call
Getmenu ()-> insertmenu (2, mf_byposition | mf_popup, (uint) menu. m_hmenu, "you ");
Menu. appendmenu (mf_string, 111, "hello ");
Menu. appendmenu (mf_string, 112, "world ");
Menu. Detach (); // This is not prompted
// Disconnect the handle from the cmenu object
Getmenu ()-> getsubmenu (0)-> appendmenu (mf_string, 114, "MFC"); // This is to add a menu item to the file submenu.
// You can also insert
Getmenu ()-> getsubmenu (0)-> insertmenu (2, mf_byposition, 115, "Dongqing ");
// Getmenu ()-> getsubmenu (0)-> deletemenu (2, mf_byposition); // use this sentence to delete the added content.
// How can I add a command response to a dynamically created menu?
// Go to resource. h and # define idm_hello 111. In this way, we have an ID number.
// Then go to the header file afx_msg void onhello (); the prototype of the message is finished, and the next step is message ing.
// On_command (idm_hello, onhello)
// Finally, the implementation of our functions,
// Void cmainframe: onhello () can be tested with MessageBox
2. Write a telephone program as follows:
Enter a blank phone number in the view and add it to the menu, and vice versa.
Capture the onchar message on the keyboard.
Cclientdc DC (this );
If (0x0d = nchar)
{
If (0 = + m_nindex) // The first press enter to add
{
M_menu.createpopupmenu ();
Getparent ()-> getmenu ()-> appendmenu (mf_popup,
(Uint) m_menu.m_hmenu, "Phonebook ");
Getparent ()-> drawmenubar ();
}
M_menu.appendmenu (mf_string, 111, m_str.left (m_str.find ('')));
// There is a space between the person name and the number at the time of input, so find the space, return the index, and then take the left side of the string
// A few characters. We will take out the name of the person.
M_str.empty ();
Invalidate (); // re-paint the window to help erase the text
}
Else // The input string is output in characters
{
M_str + = nchar;
DC. textout (0, 0, m_str );
}
Add it, awesome. Haha
Next, we need to display it back.
Here we need to store all the strings.
Use the cstringarray collection class
M_strarray.add (m_str );
I don't want to write any more, so let's get there.