vc中怎么disable菜单选项
答案:2 悬赏:60
解决时间 2021-02-12 18:53
- 提问者网友:不懂我就别说我变
- 2021-02-12 03:09
vc中怎么disable菜单选项
最佳答案
- 二级知识专家网友:心痛成瘾
- 2021-02-12 03:59
CMenu::EnableMenuItem
UINT EnableMenuItem( UINT nIDEnableItem,
UINT nEnable );
Return Value
Previous state (MF_DISABLED, MF_ENABLED, or MF_GRAYED)
or –1 if not valid.
Parameters
nIDEnableItem
Specifies the menu item to be enabled, as determined by
nEnable. This parameter can specify pop-up menu items as well as standard
menu items.
nEnable
Specifies the action to take. It can be a combination of
MF_DISABLED, MF_ENABLED, or MF_GRAYED, with
MF_BYCOMMAND or MF_BYPOSITION. These values can be combined by
using the bitwise OR operator. These values have the following meanings:
MF_BYCOMMAND Specifies that the parameter gives the command ID of
the existing menu item. This is the default.
MF_BYPOSITION Specifies that the parameter gives the position of
the existing menu item. The first item is at position 0.
MF_DISABLED Disables the menu item so that it cannot be selected
but does not dim it.
MF_ENABLED Enables the menu item so that it can be selected and
restores it from its dimmed state.
MF_GRAYED Disables the menu item so that it cannot be selected and
dims it.
Remarks
Enables, disables, or dims a menu item. The CreateMenu, InsertMenu, ModifyMenu, and LoadMenuIndirect member
functions can also set the state (enabled, disabled, or dimmed) of a menu
item.
Using the MF_BYPOSITION value requires an application to use the
correct CMenu. If the CMenu of the menu bar is used, a top-level
menu item (an item in the menu bar) is affected. To set the state of an item in
a pop-up or nested pop-up menu by position, an application must specify the
CMenu of the pop-up menu.
When an application specifies the MF_BYCOMMAND flag, Windows checks
all pop-up menu items that are subordinate to the CMenu; therefore,
unless duplicate menu items are present, using the CMenu of the menu bar
is sufficient.
Example
// The code fragment below shows how to disable (and gray out) the
// File\New menu item.
// NOTE: m_bAutoMenuEnable is set to FALSE in the constructor of
// CMainFrame so no ON_UPDATE_COMMAND_UI or ON_COMMAND handlers are
// needed, and CMenu::EnableMenuItem() will work as expected.
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(0);
submenu->EnableMenuItem(ID_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
来自MSDN
UINT EnableMenuItem( UINT nIDEnableItem,
UINT nEnable );
Return Value
Previous state (MF_DISABLED, MF_ENABLED, or MF_GRAYED)
or –1 if not valid.
Parameters
nIDEnableItem
Specifies the menu item to be enabled, as determined by
nEnable. This parameter can specify pop-up menu items as well as standard
menu items.
nEnable
Specifies the action to take. It can be a combination of
MF_DISABLED, MF_ENABLED, or MF_GRAYED, with
MF_BYCOMMAND or MF_BYPOSITION. These values can be combined by
using the bitwise OR operator. These values have the following meanings:
MF_BYCOMMAND Specifies that the parameter gives the command ID of
the existing menu item. This is the default.
MF_BYPOSITION Specifies that the parameter gives the position of
the existing menu item. The first item is at position 0.
MF_DISABLED Disables the menu item so that it cannot be selected
but does not dim it.
MF_ENABLED Enables the menu item so that it can be selected and
restores it from its dimmed state.
MF_GRAYED Disables the menu item so that it cannot be selected and
dims it.
Remarks
Enables, disables, or dims a menu item. The CreateMenu, InsertMenu, ModifyMenu, and LoadMenuIndirect member
functions can also set the state (enabled, disabled, or dimmed) of a menu
item.
Using the MF_BYPOSITION value requires an application to use the
correct CMenu. If the CMenu of the menu bar is used, a top-level
menu item (an item in the menu bar) is affected. To set the state of an item in
a pop-up or nested pop-up menu by position, an application must specify the
CMenu of the pop-up menu.
When an application specifies the MF_BYCOMMAND flag, Windows checks
all pop-up menu items that are subordinate to the CMenu; therefore,
unless duplicate menu items are present, using the CMenu of the menu bar
is sufficient.
Example
// The code fragment below shows how to disable (and gray out) the
// File\New menu item.
// NOTE: m_bAutoMenuEnable is set to FALSE in the constructor of
// CMainFrame so no ON_UPDATE_COMMAND_UI or ON_COMMAND handlers are
// needed, and CMenu::EnableMenuItem() will work as expected.
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(0);
submenu->EnableMenuItem(ID_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
来自MSDN
全部回答
- 1楼网友:白日梦制造商
- 2021-02-12 05:16
我不会~~~但还是要微笑~~~:)
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯