Create the menu with all the items that it will ever contain, then dynamically remove and insert the items as required. After loading menu, Query and maintain a copy of the menuitem(s) that will be removed.
// Obtain and keep a copy of the convert submenuitem if (!WinSendMsg (pwd->hwndAB, MM_QUERYITEM, MPFROM2SHORT (IDM_KanCnvMnu, TRUE), MPFROMP (&pwd->miCnvMnu))) { // And the convert submenu text if (!WinSendMsg (pwd->hwndAB, MM_QUERYITEMTEXT, MPFROM2SHORT (IDM_KanCnvMnu, sizeof (pwd->szCnvMnuTxt)), MPFROMP (&pwd->szCnvMnuTxt)) ){
When menu is to updated, insert/remove as necessary
// This is layout, is the submenu already in place? if (!pwd->fCnvMenu) { // The submenu is not installed, so insert the submenu WinSendMsg (pwd->hwndAction, MM_INSERTITEM, MPFROMP (&pwd->miCnvMnu), MPFROMP (pwd->szCnvMnuTxt)); // And remove the convert menuitem WinSendMsg (pwd->hwndAB, MM_REMOVEITEM, MPFROM2SHORT (IDM_KanCnv, TRUE), 0L); // Set the submenu flag pwd->fCnvMenu = TRUE; }
Credit: Matthew S. Osborn