ModifyMenu函数怎么用(200分)

  • 主题发起人 akfr_20020414
  • 开始时间
A

akfr_20020414

Unregistered / Unconfirmed
GUEST, unregistred user!
The ModifyMenu function changes an existing menu item. This function is used to specify the content, appearance, and behavior of the menu item.
The ModifyMenu function has been superseded by the SetMenuItemInfo function. You can still use ModifyMenu, however, if youdo
not need any of the extended features of SetMenuItemInfo.
BOOL ModifyMenu(
HMENU hMnu, // handle of menu
UINT uPosition, // menu item to modify
UINT uFlags, // menu item flags
UINT uIDNewItem, // menu item identifier or handle of drop-down menu or submenu
LPCTSTR lpNewItem // menu item content
);

Parameters
hMnu
Identifies the menu to be changed.
uPosition
Specifies the menu item to be changed, as determined by the uFlags parameter.
uFlags
Specifies flags that control the interpretation of the uPosition parameter and the content, appearance, and behavior of the menu item. This parameter must be a combination of one of the following required values and at least one of the values listed in the following Remarks section.
Value Meaning
MF_BYCOMMAND Indicates that the uPosition parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default if neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
MF_BYPOSITION Indicates that the uPosition parameter gives the zero-based relative position of the menu item.

uIDNewItem
Specifies either the identifier of the modified menu item or, if the uFlags parameter has the MF_POPUP flag set, the handle of the drop-down menu or submenu.
lpNewItem
Points to the content of the changed menu item. The interpretation of this parameter depends on whether the uFlags parameter includes the MF_BITMAP, MF_OWNERDRAW, or MF_STRING flag.
Value Meaning
MF_BITMAP Contains a bitmap handle.
MF_OWNERDRAW Contains a 32-bit value supplied by an application that is used to maintain additional data related to the menu item. The value is in the itemData member of the structure pointed to by the lparam parameter of the WM_MEASUREITEM or WM_DRAWITEM messages sent when the menu item is created or its appearance is updated.
MF_STRING Contains a pointer to a null-terminated string (the default).

Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
If ModifyMenu replaces a menu item that opens a drop-down menu or submenu, the function destroys the old drop-down menu or submenu and frees the memory used by it.
The application must call the DrawMenuBar function whenever a menu changes, whether or not the menu is in a displayed window. To change the attributes of existing menu items, it is much faster to use the CheckMenuItem and EnableMenuItem functions.
The following list describes the flags that may be set in the uFlags parameter:
Value Meaning
MF_BITMAP Uses a bitmap as the menu item. The lpNewItem parameter contains the handle of the bitmap.
MF_BYCOMMAND Indicates that the uPosition parameter specifies the identifier of the menu item (the default).
MF_BYPOSITION Indicates that the uPosition parameter specifies the zero-based relative position of the new menu item.
MF_CHECKED Places a check mark next to the item. If your application provides check mark bitmaps (see the SetMenuItemBitmaps function), this flag displays a checked bitmap next to the menu item.
MF_DISABLED Disables the menu item so that it cannot be selected, but this flagdo
es not gray it.
MF_ENABLED Enables the menu item so that it can be selected and restores it from its grayed state.
MF_GRAYED Disables the menu item and grays it so that it cannot be selected.
MF_MENUBARBREAK Functions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is separated from the old column by a vertical line.
MF_MENUBREAK Places the item on a new line (for menu bars) or in a new column (for a drop-down menu, submenu, or shortcut menu) without separating columns.
MF_OWNERDRAW Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then
sent to the window procedure of the owner window whenever the appearance of the menu item must be updated.
MF_POPUP Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies the handle of the drop-down menu or submenu. This flag is used to add a menu name to a menu bar or a menu item that opens a submenu to a drop-down menu, submenu, or shortcut menu.
MF_SEPARATOR Draws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
MF_STRING Specifies that the menu item is a text string;
the lpNewItem parameter points to the string.
MF_UNCHECKED Does not place a check mark next to the item (the default). If your application supplies check mark bitmaps (see the SetMenuItemBitmaps function), this flag displays an unchecked bitmap next to the menu item.

The following groups of flags cannot be used together:
?MF_BYCOMMAND and MF_BYPOSITION
?MF_DISABLED, MF_ENABLED, and MF_GRAYED
?MF_BITMAP, MF_STRING, MF_OWNERDRAW, and MF_SEPARATOR
?MF_MENUBARBREAK and MF_MENUBREAK
?MF_CHECKED and MF_UNCHECKED
 
BOOL ModifyMenu(HMENU hMenu,int nPosition,int wFlags,int wIDNewItem,LPCTSTR "");
说明
改变菜单条目。
返回值
Long,非零表示成功,零表示失败。会设置GetLastError

参数 类型及说明
hMenu Long, 菜单句柄
nPosition 欲改变的菜单条目的标识符。
如在wFlags参数中指定了MF_BYCOMMAND,
这个参数就代表欲改变的菜单条目的命令ID。
如设置的是MF_BYPOSITION,
这个参数就代表菜单条目在菜单中的位置(第一个条目的位置为零)
wFlags 一系列常数标志的组合。详见菜单常数标志表
wIDNewItem 指定菜单条目的新命令ID。
如在wFlags参数中指定了MF_POPUP标志,
就应是一个弹出式菜单的句柄
lpString String或Long, 如在wFlags参数中指定了MF_STRING标志,
就代表欲设置到菜单的字串。
如设置的是MF_BITMAP,就代表一个Long变量,
其中包含了一个位图句柄。
如设置的是MF_OWNERDRAW,那么这个值就会包括到
DRAWITEMSTRUCT和MEASUREITEMSTRUCT结构中,
并由windows在条目需要重画的时候发出
注解
标志的下述组合形式是不允许的:
MF_BYCOMMAND和MF_BYPOSITION;
MF_CHECKED和MF_UNCHECKED;
MF_MENUBARBREAK和MF_MENUBREAK;
MF_DISABLED,MF_ENABLED和MF_GRAYED;
MF_BITMAP,MF_STRING,MF_OWNERDRAW和MF_SEPARATOR

菜单常数标志表
MF_BITMAP 菜单条目是一幅位图。一旦设入菜单,这幅位图就绝对不能删除。
MF_BYCOMMAND 菜单条目由菜单的命令ID指定
MF_BYPOSITION 菜单条目由条目在菜单中的位置决定。零代表菜单中的第一个条目
MF_CHECKED 检查指定的菜单条目。
MF_DISABLED 禁止指定的菜单条目。
MF_ENABLED 允许指定的菜单条目。
MF_GRAYED 禁止指定的菜单条目,并用浅灰色描述它。
MF_MENUBARBREAK 在弹出式菜单中,将指定的条目放置于一个新列,
并用一条垂直线分隔不同的列
MF_MENUBREAK 在弹出式菜单中,将指定的条目放置于一个新列。
在顶级菜单中,将条目放置到一个新行
MF_OWNERDRAW 创建一个物主绘图菜单(由您设计的程序负责描绘每个菜单条目)
MF_POPUP 将一个弹出式菜单置于指定的条目。
可用于创建子菜单及弹出式菜单
MF_SEPARATOR 在指定的条目处显示一条分隔线
MF_STRING 在指定的条目处放置一个字串。
MF_UNCHECKED 检查指定的条目。
 
英语我看不懂
 
顶部