Current location - Recipe Complete Network - Complete cookbook of home-style dishes - VC++ Loading Custom Menu and How to Create Shortcut Menu Manually
VC++ Loading Custom Menu and How to Create Shortcut Menu Manually
In VC++, add a menu to an application:

Load a user-defined menu

Load the user-defined menu in the OnCreate function of the framework class CMainFrame. Double-click the OnCreate function of the CMainFrame class in the left workspace. Edit code is as follows:

DockControlBar(& amp; m _ wndToolBar);

CMenu menu; //Declare menu objects

Menu. load menu(CG _ IDR _ POPUP _ MY _ VIEW); //Add the code in bold black with the user-defined menu name in brackets.

this-SetMenu(& amp; Menu); //Set the custom menu to replace the existing menu and return 0; ; Note: If you want to create a cascading menu, you can choose the pop-up option.

Response of right-click menu:

Add the response function OnRButtonDown of WM_RBOTTONDOWN to the view class, and add code in it, as shown below:

CMenu menu; //Define menu objects

Menu. load menu(IDR _ my menu); //Load the menu resource and define the menu name in brackets.

CMenu *pSubMenu=menu。 get submenu(0); //Get the first top-level menu

client to screen(& amp; Point); //Convert coordinates

pSubMenu-trackppopupmenu(TPM _ left align | TPM _ left button,

point.x,point.y,get parent()); //popup menu

CView::onrbtuoundown(nFlags,point);

Menu item properties dialog box: several groups of option IDs (menu item ID): Generally speaking, the selection of menu ID should follow the following principles: ID_ top menu name _ lower menu item name (_ lower menu item name). For example: ID_LOLOR_RED. Note: the pop-up menu does not need an ID number.

Title (name of menu item): It can be English, Chinese, numbers, symbols, etc. Note: Users can define shortcut keys for menu items in the title text box and enter "&"before the letter of the menu title. Do it. If the menu is in Chinese, you must enclose the description of the shortcut key in parentheses, for example, the shortcut key of the "New" menu item uses "(&; N) ". Tip: There is also a string of characters "\tCtrl+N" in the title text box to indicate the shortcut key of this menu item. Shortcut keys can execute menu items directly without opening the menu.

Separator check box: If this check box is selected, the menu item will become a separator and the original menu item will be lost. If the user wants to add a separation line, he can drag a blank menu to the position where the separation line is needed, and then select the separator check box of the blank menu.

Pop-up check box: if this check box is selected, the menu item will become a pop-up menu, that is, clicking this menu will pop up the next submenu. The default top-level menu in Visual C++6.0 is pop-up menu.

Inactive check box: When this check box is selected, the initial state of the surface menu item is inactive.

Selected check box: This check box is a check mark for the initial value of the menu. Selecting this check box will put a check mark on the left side of the menu item.

Gray check box: If this check box is selected, the menu item will be grayed out, indicating that the initial state of the menu is inaccessible. If this check box is selected, the menu must be inactive, so the inactive check box is not available at this time.

Help check box: Select this check box and the menu will appear on the right side of the menu bar.

Break: When there are too many menu items in a menu, putting them in one column will feel long and crowded. At this time, you can consider dividing it into two columns to show it. Break plays this role. The Break option corresponds to a combo box, and * * * has three options, namely none, column and bar.

None: the default option, which means no division.

Columns: column splitting. When this item is selected, the menu item below the selected menu item will start a new line. For example, in the file menu, select the result of printing a menu item.

Parallel format: similar to column, it is also a column. Just different from Column, there is a vertical line between the two columns. Text box: You can enter text in the text box after the prompt. When the program is running, when the mouse moves to the menu item, the function prompt of the menu will be given in the bottom status bar.