GetMenuStringA function (winuser.h)

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.


int GetMenuStringA(
  [in]            HMENU hMenu,
  [in]            UINT  uIDItem,
  [out, optional] LPSTR lpString,
  [in]            int   cchMax,
  [in]            UINT  flags


[in] hMenu


A handle to the menu.

[in] uIDItem

Type: UINT

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

[out, optional] lpString


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.

[in] 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.

[in] flags

Type: UINT

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

Value Meaning
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.
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.


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.


For an example, see Creating User Editable Accelerators.


The winuser.h header defines GetMenuString as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.


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
API set ext-ms-win-ntuser-menu-l1-1-3 (introduced in Windows 10, version 10.0.14393)

See also