The menu bar that appears at the top of a window is an application''s top-level menu, and the commands in it are called top-level menu items. Menu dialog box property sheet - Trần Anh Tuấn A presents about it.
Trần Anh Tuấn A Menu The menu bar that appears at the top of a window is an application's toplevel menu, and the commands in it are called toplevel menu items. The menu that appears when a toplevel menu item is clicked is a dropdown menu, and items in that menu are referred to as menu items Menu items are identified by integer values called menu item IDs or command IDs Menu Windows also supports popup menus that look like dropdown menus but can be popped up anywhere on the screen Cascading menus are actually Pull_down menus that are submenus Pull_down Menu Cascading Menu Popup Menu Menu You can create a menu in an MFC application in three ways: You can create a menu programmatically, piecing it together using CreateMenu, InsertMenu, and other CMenu functions You can initialize a series of data structures defining the menu's contents and create the menu with CMenu::LoadMenuIndirect You can create a menu resource and load the resulting menu into the application at run time (common use) Create Menu Use resource to create menu Apply Menu Method for loading a toplevel menu and attaching it to a window is to construct a CMenu object Call CMenu::LoadMenu to load the menu resource, and call CWnd::SetMenu, like this: CMenu menu; menu.LoadMenu (IDR_MENU1); SetMenu (&menu); CMenu::Detach is called to detach the menu from the CMenu object so that the menu won't be destroyed prematurely when menu goes out of scope Menu Functions WM_INITMENU WM_INITMENUPOPUP WM_MENUSELECT WM_COMMAND The most important message of all is the WM_COMMAND message sent when the user selects an item from the menu More Menu Function Sometimes it's more efficient to process a group of menu item IDs with a single command handler than to provide a separate member function for each ID: More Menu Function In many applications, menu items must be constantly updated to reflect internal states of the application or its data. When a color is selected from a Color menu, for example, the corresponding menu item should be checked or bulleted to indicate which color is currently selected More Menu Function MFC provides a similar but more convenient mechanism for keeping menu items updated. Through ON_UPDATE_COMMAND_UI macros in the message map, you can designate selected member functions to serve as update handlers for individual menu items. When the user pulls down a menu, MFC traps the ensuing WM_INITMENUPOPUP message and calls the update handlers for all the items in the menu More Menu Function More Menu Function SetCheck is just one of the CCmdUI methods that you can use to update a menu item. The following table shows a complete list, along with a description of each function's effect on a menu item Model Dialog Creating a modal dialog box is a threestep process: Create a dialog box in Resource Use Classwinzard to creayt a class for dialog and use it to define the dialog’s behavior Construct an class object Call CDialog::DoModal to display the dialog box Model Dialog Once you've defined the dialog box template and declared the dialog class, creating a modal dialog box is a simple matter of constructing an object from your CDialogderived class and calling that object's DoModal function. DoModal doesn't return until after the dialog box is dismissed. When DoModal does return, its return value is the value that was passed to EndDialog More Model Dialog Box By default, the only values DoModal will return are IDOK and IDCANCEL. However, you can write your dialog class to return other values by calling EndDialog with a value other than IDOK or IDCANCEL. Dialog Data Exchange and Dialog Data Validation Modeless Dalog Modal and modeless dialog boxes are more alike than they are different. The key differences between them include the following: Modeless dialog boxes are dismissed by calling DestroyWindow, not EndDialog. You mustn't allow CDialog::OnOK or CDialog::OnCancel to be called on a modeless dialog box, because both call EndDialog. Whereas a modal dialog box is displayed by calling CDialog::DoModal, modeless dialog boxes are displayed with CDialog::Create. Unlike DoModal, which doesn't return until the dialog box is dismissed, Create returns as soon as the dialog box is created Modeless Dialog Step 1: Create a Dialog Box (like Model Dialog) Step 2: Create a class for dialog (Example CModeless) Step 3: Create Dialog object Header file CModeless *m_pmodeless; Implement file m_pmodeless = new CModeless(this); m_pmodeless>Create(CModeless::IDD); Step 4: Show and Hide this Dialog m_pmodelessShowWindow(SW_SHOW); m_pmodelessShowWindow(SW_HIDE); Property Sheet Please see the example in Project 1 ... DestroyWindow, not End Dialog. You mustn't allow CDialog::OnOK or CDialog::OnCancel to be called on a modeless dialog box, because both call EndDialog. Whereas a modal dialog box is displayed by calling CDialog::DoModal, modeless dialog boxes are ... IDOK and IDCANCEL. However, you can write your dialog class to return other values by calling EndDialog with a value other than IDOK or IDCANCEL. Dialog Data Exchange and Dialog Data Validation... with a description of each function's effect on a menu item Model Dialog Creating a modal dialog box is a threestep process: Create a dialog box in Resource Use Classwinzard to creayt a class for dialog and use it