MenuAddStringfunction
Adds a string or separator to an existing menu.
Syntax
FUNCTION MenuAddString (BYVAL hMenu AS HMENU, BYREF wszText AS WSTRING, BYVAL id AS LONG, BYVAL fState AS UINT, BYVAL item AS LONG = 0, BYVAL fByPosition AS BOOLEAN = FALSE) AS BOOLEAN
Parameters
| Name | Description | |
|---|---|---|
hMenu | Handle of the parent menu to which the string should be added. | |
wszText | Text to display in the parent menu. An ampersand (&) may be used in the string to make the following letter into a command accelerator (hot-key). The letter is underscored to signify that it is an accelerator. To create a horizontal separator instead of a text string, set wszText = "-", id = 0, fState = 0. Keyboard accelerators can be indicated in the text of a menu item, for the reference of the user. To include a keyboard accelerator description in a menu string, separate it from the menu item text with a CHR(9) character. For example: MenuAddString hMenu, "Cu&t" & CHR(9) & "CTRL+X", id, fState. | |
id | The unique identifier for the menu item. When a menu item is selected, id is sent to the parent dialog callback function to notify the dialog which option was selected. | |
fState | The initial state of the menu item. It can be one or more of the following, combined together with the OR operator to form a bitmask: MFS_CHECKED: Place a checkmark next to the item. MFS_DEFAULT: The default menu item, displayed in bold. Only one item may be the default. MFS_DISABLED: Disable the menu item so that it cannot be selected. MFS_ENABLED: Enable the menu item so that it can be selected. MFS_GRAYED: Disable the menu item so that it cannot be selected, and draw it in a "grayed" state to indicate this. MFS_HILITE: Highlight the menu item. MFS_UNCHECKED: Do not place a checkmark next to the item. MFS_UNHILITE: Item is not highlighted. A state value of zero (0) provides MFS_ENABLED, MFS_UNCHECKED, and MFS_UNHILITE. | |
item | Optional position in the parent menu, where the menu item should be inserted. If the fByPosition option is used, the menu item is inserted prior to the menu item identifier specified by item. Otherwise, the menu item is inserted at the physical position within the parent menu, where position = 1 for the first position, position = 2 for the second, and so on. If position is not specified then the popup menu is appended to the end of the menu. | |
fByPosition | The meaning of item. If this parameter is FALSE, item is a menu item identifier. Otherwise, it is a menu item position, where position = 1 for the first position, position = 2 for the second, and so on. |
Return value
Returns TRUE if the function succeeds; FALSE otherwise.
Description
Adds a string or separator to an existing menu. A string may contain an optional command accelerator key, and also describe an equivalent keyboard accelerator combination.
Remarks
The application must call the MenuDrawBar statement whenever a menu changes, whether or not the menu is in a displayed dialog.
Examples
MenuAddString hPopup1, "&Open", ID_OPEN, MF_ENABLED
MenuAddString hPopup1, "&Exit", ID_EXIT, MF_ENABLED, 1, TRUE ' insert by position MenuAddString hPopup1, "&Exit", ID_EXIT, MF_ENABLED, ID_OPEN, FALSE ' insert by identifier
Insert the item before the ID_OPEN item
Reference
- Defined in AfxNova/AfxMenu.inc:949
- Documented in Windows/Windows GUI/Menu Procedures.md
- Topic: About Menus