1
2
3
hmenu = GetMenu(hWnd);
haddmenu = CreateMenu();
AppendMenu(haddmenu, MF_ENABLED, 4, "求和");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HMENU hmenu, haddmenu/*添加的菜单句柄*/;
switch(message)
{
case WM_COMMAND :
switch (LOWORD(wParam))
{
case 1 : // 添加菜单项
hmenu = GetMenu(hWnd);
haddmenu = CreateMenu();
AppendMenu(haddmenu, MF_ENABLED, 4, "求和");
AppendMenu(haddmenu, MF_ENABLED, 5, "求差");
InsertMenu(hmenu, 2, MF_POPUP | MF_BYPOSITION, (UINT)haddmenu, "统计计算");
EnableMenuItem(hmenu, 1, MF_GRAYED);
EnableMenuItem(hmenu, 2, MF_ENABLED);
DrawMenuBar(hWnd);
break;
case 2 : // 删除菜单项
hmenu = GetMenu(hWnd);
DeleteMenu(hmenu, 2, MF_BYPOSITION);
EnableMenuItem(hmenu, 1, MF_ENABLED);
EnableMenuItem(hmenu, 2, MF_GRAYED);
DrawMenuBar(hWnd);
break;
}
break;
}
}