CMenu mainMenu; mainMenu.AppendMenu(MF_STRING, 1, "Open"); mainMenu.AppendMenu(MF_STRING, 2, "Save"); mainMenu.AppendMenu(MF_SEPARATOR); mainMenu.AppendMenu(MF_STRING, 3, "Exit");
CMenu fileMenu; fileMenu.CreatePopupMenu(); fileMenu.AppendMenu(MF_STRING, 1, "New"); fileMenu.AppendMenu(MF_STRING, 2, "Open"); fileMenu.AppendMenu(MF_STRING, 3, "Save"); fileMenu.AppendMenu(MF_STRING, 4, "Save As"); fileMenu.AppendMenu(MF_SEPARATOR); fileMenu.AppendMenu(MF_STRING, 5, "Exit"); mainMenu.AppendMenu(MF_POPUP, (UINT_PTR) fileMenu.GetSafeHmenu(), "File");
void CMyApp::OnCommand(UINT nCmdID) { switch (nCmdID) { case 1: // Handle "Open" command break; case 2: // Handle "Save" command break; case 3: // Handle "Exit" command break; default: // Handle other commands break; } }This code defines a function that handles menu commands. When a user clicks on a menu item, the corresponding command ID is passed to this function. The function then switches on the command ID to determine which command was clicked, and executes the appropriate code. In summary, CMenu Menu is a part of the C++ Standard Library that allows developers to create menus and submenu items in console applications. It provides a simple and straightforward way to handle user input in a structured and organized manner.