title: WINAPI, remove popup menu from menu
body: <p>I would like to have dynamic menu in my application. This dynamic menu should contain popupmenus which will be added and removed on the fly. For the first approach I made dynamic menu created with single menu items.</p>
  
  <pre><code>AppendMenu(menu, MF_STRING, item_id, "TEST");
  </code></pre>
  
  <p>I have created algorithm which generate item_id and store them in array, so I could remove them by</p>
  
  <pre><code>DeleteMenu(menu, id_to_be_deleted, MF_BYCOMMAND);
  </code></pre>
  
  <p>I do not see any pitfalls of this implementation and I am happy with it. But then stuck with final implementation. I would like my menus would be popup menus.</p>
  
  <pre><code>new_popup_menu = CreatePopupMenu();
  AppendMenu(new_popup_menu, MF_STRING, 1, "TEST1");
  AppendMenu(new_popup_menu, MF_STRING, 2, "TEST2");
  AppendMenu(new_popup_menu, MF_STRING, 3, "TEST3");
  AppendMenu(menu, MF_STRING|MF_POPUP, 
            (UINT_PTR)new_popup_menu, "dynamic menu");
  </code></pre>
  
  <p>This code works as expected, but I have no idea how to remove "new_popup_menu" from "menu" since the "UINT_PTR uIDNewItem" parameter of AppendMenu now is used as handle to submenu, not ID and cannot be used with DeleteMenu+MF_BYCOMMAND.
  Is there any way to remove this submenu item other then DeleteMenu+MF_BYPOSITION?
  Is there a way to get menu item position by handle which is returned by CreatePopupMenu())?
  I feel implementation algorithm of tracking which menu is on which position is pain in the ass. Since Windows has API to insert the menu after other specific menu, recreating whole menu tree is a waste of CPU time.</p>