I am writing a program in c++ with the Win32 API I created a popup menu with multiple submenus the submenus open up fine but when I open one and go to another they just overlap each other
Heres a screenshot and my code

Name:  examplepic.png
Views: 162
Size:  28.0 KB


Code:
case WM_RBUTTONDOWN:
		{
		
		HMENU hPopupMenu = CreatePopupMenu();
		HMENU hSubMenu = CreatePopupMenu();
		HMENU hLetterMenu = CreatePopupMenu();
		HMENU hNumberMenu = CreatePopupMenu();
		HMENU hBrowserMenu = CreatePopupMenu();
		HMENU hToggleMenu = CreatePopupMenu();
		HMENU hFunctionMenu = CreatePopupMenu();
		HMENU hMediaMenu = CreatePopupMenu();
		HMENU hComboMenu = CreatePopupMenu();
		HMENU hMouseMenu = CreatePopupMenu();

		
		AppendMenu(hPopupMenu,  MF_STRING | MF_POPUP, UINT_PTR(hLetterMenu), L"Letter Keys");
		AppendMenu(hPopupMenu,  MF_STRING |MF_POPUP, UINT_PTR(hNumberMenu), L"Number Keys");
		AppendMenu(hPopupMenu,  MF_STRING | MF_POPUP, UINT_PTR(hToggleMenu), L"Toggle Keys");
		AppendMenu(hPopupMenu,  MF_STRING | MF_POPUP, UINT_PTR(hMediaMenu), L"Media Keys");
		AppendMenu(hPopupMenu,  MF_STRING | MF_POPUP, UINT_PTR(hFunctionMenu), L"Function Keys");
		AppendMenu(hPopupMenu,  MF_STRING | MF_POPUP, UINT_PTR(hComboMenu), L"Combo Keys");
		AppendMenu(hPopupMenu,  MF_STRING | MF_POPUP, UINT_PTR(hMouseMenu), L"Mouse Buttons");

		for(int j = 0; j < 26; ++j)
		{
			AppendMenu(hLetterMenu,  MF_STRING , 0,letterarray[j]);
		}

		for(int j = 0; j < 10; ++j)
		{
			AppendMenu(hNumberMenu,  MF_STRING, 0,numberArray[j]);
		}

		for(int j = 0; j < 8; ++j)
		{
			AppendMenu(hMediaMenu,  MF_STRING, 0, mediaArray[j]);
		}

		for(int j = 0; j < 5; ++j)
		{
			AppendMenu(hMouseMenu,  MF_STRING, 0, mouseArray[j]);
		}

		for(int j = 0; j < 12; ++j)
		{
			AppendMenu(hFunctionMenu,  MF_STRING, 0, functionArray[j]);
		}

		for(int j = 0; j < 3; ++j)
		{
			AppendMenu(hToggleMenu,  MF_STRING, 0, toggleArray[j]);
		}

		SetForegroundWindow(ghMainWnd);
		
		GetCursorPos(&mouseposition);
		TrackPopupMenu(hPopupMenu, TPM_TOPALIGN | TPM_LEFTALIGN , mouseposition.x, mouseposition.y, 0, hWnd, NULL);
		
		
		return 0;
		}
the arrays are LPCWSTR arrays containing the strings to be drawn