Dancing

I have enabled the key in the registry and this works fine. I am getting the popup whenever I hit Control-Shift. Its easy to find and add new menu items to the right context Project menu, and I have done that, however there is a submenu (A&dd) which is where I REALLY want to put the items. How do I find the GUID and ID of the submenu I click on A&dd and I get the menu id of the A&dd item, but the FindCommandBar command returns null when I use that GUID and menu item id.

Re: Visual Studio Extensibility Problem getting command bar with EnableVSIPLogging

Ed Dore

Guid projCtxMenu = new Guid("D309F791-903F-11D0-9EFC-00A0C911004F");

uint menuID = 850;

The above values work for me. I got these from holding down the CTRL+SHIFT key "after the Project context menu was displayed, and just before hovering over the Add menu item. Also, be sure to call something like the following:

CommandBar menuBarCommandBar = ((CommandBars)_applicationObject.CommandBars)["MenuBar"];

To ensure the CommandBar stuff is properly initialized. The CommandBars are created on demand, and aren't available until invoked from the DTE automation model. So calling IVsProfferCommands.FindCommandBar won't find any CommandBars until an automation call like the one above is made first.

Sincerely,






Re: Visual Studio Extensibility Problem getting command bar with EnableVSIPLogging

Dancing

I am still having the same problem. I also got the 850 value using the Ctrl+Shift just before selecting the A&dd menu item. This is a code snippet from my program:

DEFINE_GUID(PRJ_MENU_GROUP, 0xD309F791, 0x903F, 0x11D0, 0x9E, 0xFC, 0x00, 0xA0, 0xC9, 0x11, 0x00, 0x4F);

//static int const knProjectMenuID( 1026 );

static int const knProjectMenuID( 850 );

extern CAddInModule _AtlModule;

void CConnect::InstallUI()

{

// ensure the commandbar automation stuff has been initialized

CComQIPtr<_CommandBars> pCommandBars;

HRESULT hr = g_pDTE->get_CommandBars((IDispatch**)&pCommandBars);

/// Find the MenuBar command bar. This makes sure that the DTE is properly initialized.

CComPtr<CommandBar> pMenuBarCommandBar;

hr = pCommandBars->get_Item(CComVariant(L"MenuBar"), &pMenuBarCommandBar);

if( SUCCEEDED( hr ) && pMenuBarCommandBar )

{

// get IServiceProvider from DTE object

CComQIPtr<IServiceProvider> pServiceProvider(g_pDTE);

// get IVsProfferCommands interface

CComPtr<IVsProfferCommands> pProfferCommands;

hr = pServiceProvider->QueryService(IID_IVsProfferCommands, IID_IVsProfferCommands, (void**)&pProfferCommands);

ATLASSERT(hr==S_OK);

// get CommandBar of Project Context menu

GUID guidCmdGroup = PRJ_MENU_GROUP;

CComPtr<CommandBar> pCommandBar;

hr = pProfferCommands->FindCommandBar(NULL, &guidCmdGroup, knProjectMenuID, (IDispatch**)&pCommandBar);

ATLASSERT(hr==S_OK);

The FindCommandBar is returning E_FAIL. This works like a charm if the knProjectMenuID == 1026.

Any suggesstions I can post the entire add-in if that would help. Its not much more than this.





Re: Visual Studio Extensibility Problem getting command bar with EnableVSIPLogging

Dancing

Anyone have any ideas on this For now I am simply adding the command to the Project menu, but I would really like to add it to its proper place.



Re: Visual Studio Extensibility Problem getting command bar with EnableVSIPLogging

Ed Dore

I could have sworn I tested this before my earlier post, by plugging in that 850 value, but I tried it again today, and I see the E_FAIL as well. After a bit more digging I realized that the Add menu is not a context menu, but a cascaded menu. There's no CommandBar object, because it's not a context or dropdown menu. This is why that FindCommandBar call fails.

Once you have Project context menu from my earlier example, just retrieve the Add command, convert it to a CommandBarPopup object, and add your menu to it's Controls collection. For example:

void CConnect::InstallUI()

{

// ensure the commandbar automation stuff has been initialized

CComQIPtr<_CommandBars> pCommandBars;

HRESULT hr = m_pDTE->get_CommandBars((IDispatch**)&pCommandBars);

// get IServiceProvider from DTE object

CComQIPtr<IServiceProvider> pServiceProvider(m_pDTE);

// get IVsProfferCommands interface

CComPtr<IVsProfferCommands> pProfferCommands;

hr = pServiceProvider->QueryService(IID_IVsProfferCommands, IID_IVsProfferCommands, (void**)&pProfferCommands);

ATLASSERT(hr==S_OK);

// get CommandBar of Project Context menu

GUID guidCmdGroup = PRJ_MENU_GROUP;

CComPtr<CommandBar> pCommandBar;

hr = pProfferCommands->FindCommandBar(NULL, &guidCmdGroup, 1026, (IDispatch**)&pCommandBar);

ATLASSERT(hr==S_OK);

// get CommandBarControls collection

CComPtr<CommandBarControls> pCmdBarControls;

hr = pCommandBar->get_Controls(&pCmdBarControls);

ATLASSERT(hr==S_OK);

// get CommandBarControl representing the Add menu item

CComPtr<CommandBarControl> pAddControl;

hr = pCmdBarControls->get_Item(CComVariant(_T("Add")), &pAddControl);

ATLASSERT(hr==S_OK);

// convert to a CommandBarPopup

CComQIPtr<CommandBarPopup> pCmdBarPopup(pAddControl);

// add Hello Button to the Add menu's Controls collection.

CComVariant varMissing(DISP_E_PARAMNOTFOUND,VT_ERROR);

CComPtr<CommandBarControls> pAddMenuControls;

hr = pCmdBarPopup->get_Controls(&pAddMenuControls);

ATLASSERT(hr==S_OK);

hr = pAddMenuControls->Add(CComVariant(msoControlButton), varMissing, varMissing, CComVariant(1), CComVariant(VARIANT_TRUE), (CommandBarControl**)&m_pHelloBtn);

ATLASSERT(hr==S_OK);

// create the CommandBarButton control (our Hello Button)

// CComVariant varMissing(DISP_E_PARAMNOTFOUND,VT_ERROR);

// hr = pCmdBarControls->Add(CComVariant(msoControlButton), varMissing, varMissing, CComVariant(1), CComVariant(VARIANT_TRUE), (CommandBarControl**)&m_pHelloBtn);

// ATLASSERT(hr==S_OK);

// initialize the button's properties.

hr = m_pHelloBtn->put_Caption(CComBSTR(_T("Hello Visual Studio")));

hr = m_pHelloBtn->put_FaceId(1845);

hr = m_buttonEventsSink.DispEventAdvise(m_pHelloBtn);

}

Sincerely,






Re: Visual Studio Extensibility Problem getting command bar with EnableVSIPLogging

Dancing

That worked like a charm! Thanks so much for all your time and help.