GetMenuStringA function

Copies the text string of the specified menu item into the specified buffer.

Note  The GetMenuString function has been superseded. Use the GetMenuItemInfo function to retrieve the menu item text.
 

Syntax

int GetMenuStringA(
  HMENU hMenu,
  UINT  uIDItem,
  LPSTR lpString,
  int   cchMax,
  UINT  flags
);

Parameters

hMenu

Type: HMENU

A handle to the menu.

uIDItem

Type: UINT

The menu item to be changed, as determined by the uFlag parameter.

lpString

Type: LPTSTR

The buffer that receives the null-terminated string. If the string is as long or longer than lpString, the string is truncated and the terminating null character is added. If lpString is NULL, the function returns the length of the menu string.

cchMax

Type: int

The maximum length, in characters, of the string to be copied. If the string is longer than the maximum specified in the nMaxCount parameter, the extra characters are truncated. If nMaxCount is 0, the function returns the length of the menu string.

flags

Type: UINT

Indicates how the uIDItem parameter is interpreted. This parameter must be one of the following values.

Value Meaning
MF_BYCOMMAND
0x00000000L
Indicates that uIDItem gives the identifier of the menu item. If neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified, the MF_BYCOMMAND flag is the default flag.
MF_BYPOSITION
0x00000400L
Indicates that uIDItem gives the zero-based relative position of the menu item.

Return Value

Type: int

If the function succeeds, the return value specifies the number of characters copied to the buffer, not including the terminating null character.

If the function fails, the return value is zero.

If the specified item is not of type MIIM_STRING or MFT_STRING, then the return value is zero.

Remarks

The nMaxCount parameter must be one larger than the number of characters in the text string to accommodate the terminating null character.

If nMaxCount is 0, the function returns the length of the menu string.

Security Warning

The lpString parameter is a TCHAR buffer, and nMaxCount is the length of the menu string in characters. Sizing these parameters incorrectly can cause truncation of the string, leading to possible loss of data.

Examples

For an example, see Creating User Editable Accelerators.

Requirements

   
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll

See Also

Conceptual

GetMenuItemID

Menus

Reference