VS 2008 Addin & # 8594; How to add a submenu at a specific position in the context menu?

I am working on an add-on for Visual Studio 2008 and want to add a permanent submenu to contain my context-sensitive commands in several context menus (such as "Project", "Item", ...).

I had no problems adding this submenu to the top of the context menu or to the bottom of it. I use:

 mPlugin.Commands.AddCommandBar(_MenuName, vsCommandBarType.vsCommandBarTypeMenu, commandBar, desiredSubmenuPosition); /*desiredSubmenuPosition = 1 or desiredSubmenuPosition = commandBar.Controls.Count+1 work perfectly fine.

However, I want to add my submenu right before the last separator of the context menu. To do this, I find all the controls in which the BeginGroup matches true, and get the control that has the largest index. Then I add my submenu to the found index-1 using the above method. But something is wrong. For some context menus, it works fine; for others, it creates my submenu in the wrong place (I'm sure that I will find the right index to insert ...).

Is there a proper way to do this?

+5
source share

All Articles