Export (0) Print
Expand All

GetMenuString 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 WINAPI GetMenuString(
  _In_       HMENU hMenu,
  _In_       UINT uIDItem,
  _Out_opt_  LPTSTR lpString,
  _In_       int nMaxCount,
  _In_       UINT uFlag
);

Parameters

hMenu [in]

Type: HMENU

A handle to the menu.

uIDItem [in]

Type: UINT

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

lpString [out, optional]

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.

nMaxCount [in]

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.

uFlag [in]

Type: UINT

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

ValueMeaning
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]

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

Unicode and ANSI names

GetMenuStringW (Unicode) and GetMenuStringA (ANSI)

See also

Reference
GetMenuItemID
Conceptual
Menus

 

 

Community Additions

ADD
Show:
© 2014 Microsoft