Nested menus

I have started working on an app that needs multiple levels of nested menus created from a left click on the app's icon in the taskbar's status area. From what I can tell so far my best bet is to create menus using the CreatePopupMenu() function, fill them using the AppendMenu function, and display them using the TrackPopupMenu function. The problem is that each time I display a new menu, the old one disappears. While this isn't the end of the world, it's not the behavior I've come to expect of apps based on my experience with other nested menu systems. In case you're wondering, I did turn on the TPM_RECURSE flag. Here is the relevant code:

In the window's callback function
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
30
31
32
		case IconMessage:
			MyTree.Load("MenuFile.txt");
			if (lParam == WM_RBUTTONDOWN)
			{
				std::cout<<"It's a right click."<<std::endl;
			}
			else if (lParam == WM_LBUTTONDOWN)
			{
					HMENU myMenu = CreatePopupMenu();
					HMENU nextLevel = CreatePopupMenu();
					AppendMenu(myMenu, MF_STRING, 3, TEXT("I'm a menu item"));
					AppendMenu(myMenu, MF_STRING, (UINT_PTR)nextLevel, TEXT("NextLevel"));
					AppendMenu(nextLevel, MF_STRING, 4, TEXT("More menu items"));
					AppendMenu(nextLevel, MF_STRING, 5, TEXT("Even more menu items"));
			}
			break;
		case WM_COMMAND:
			switch (LOWORD(wParam) )
			{
				case 3:
				//break;
				case 4:
				//break;
				case 5:
				std::cout<<"got a menu click"<<std::endl;
				break;
				default:
				RECT uselessArg = {0};
				POINT cursorPos;
				GetCursorPos(&cursorPos);
				TrackPopupMenu(((HMENU) LOWORD(wParam)), TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON|TPM_RECURSE, cursorPos.x, cursorPos.y, 0, hwnd, &uselessArg);
			}

Topic archived. No new replies allowed.