InsertItem Function: Insert Before Does not Work

Summary

Id: 7.4
Type: Bug Bug
Current Status: Open

Detail

6 May 2003 Open John Little

I have noticed a problem with the "InsertItem" function, when trying to insert "before" an existing item, it doesn't seem to work. I have checked through the code and found 3 possible problems here are the problems with my solution. I thought you might like to know this and the fix.

Problem is in "pInsertNewMenuitem"

.... Code Skipped ' Check for position: lC = GetMenuItemCount(hMenu) #if true Then lPosition = lC ' assume we add to the end ^^^^^^^^^^^^^ added so that we always add to end if no menu located #endif For iMenu = 0 To lC - 1 tMII.cbSize = LenB(tMII) tMII.fMask = MIIM_ID GetMenuItemInfo hMenu, iMenu, True, tMII #if false Then vvvvvvvvvvvv Original code looks for lParentId If tMII.wID = m_tMI(lIndexBefore).lParentId Then #else If tMII.wID = m_tMI(lIndexBefore).lID Then ^^^^^^^^^^^^ My fix look for lId #endif lPosition = iMenu Exit For End If Next iMenu..... Code skipped #if false Then vvvvvvvvvvvv Original code couldn't add before if before was last item If lPosition = lC - 1 Then #else If lPosition >= lC Then ^^^^^^^^^^^^ My fix allow to add before last item #endif ' adding to the end: lR = InsertMenuItem(hMenu, -1, True, tMII) Else ' inserting: lR = InsertMenuItem(hMenu, lPosition, True, tMII) End If