C ++ Windows API:禁用的菜单呈灰色?

时间:2018-12-07 13:44:22

标签: c++ windows winapi

我正在测试Windows API的菜单状态(已禁用,呈灰色,选中...),但是有些我不了解。 documentation指出MF_DISABLED不会使物品变灰,这是我得到的:

enter image description here

使用以下代码:

HMENU menuBar = CreateMenu();
HMENU hopMenu = CreateMenu();

AppendMenuW(menuBar, MF_POPUP, (UINT_PTR)hopMenu, L"hop");
AppendMenuW(hopMenu, MF_STRING, 0, L"Enabled");

AppendMenuW(hopMenu, MF_STRING | MF_DISABLED, 1, L"Disabled");
AppendMenuW(hopMenu, MF_STRING | MF_GRAYED, 2, L"Grayed");
AppendMenuW(hopMenu, MF_STRING | MF_CHECKED, 3, L"Checked");

AppendMenuW(hopMenu, MF_STRING | MF_DISABLED | MF_CHECKED, 4, L"Disabled && Checked");
AppendMenuW(hopMenu, MF_STRING | MF_DISABLED | MF_GRAYED, 5, L"Disabled && Grayed");

AppendMenuW(hopMenu, MF_STRING | MF_CHECKED | MF_GRAYED, 6, L"Checked && Grayed");

SetMenu(hwnd, menuBar);

那么如何使禁用的菜单项不显示为灰色?

1 个答案:

答案 0 :(得分:7)

这两个现在相同。有关更多信息,请参见tagMENUITEMINFOA

MFS_DISABLEDMFS_GRAYED都显示为灰色,因为它们表示0x00000003L的相同值