// Connect.cpp : Implementation of CConnect #include "stdafx.h" #include "AddIn.h" #include "Connect.h" extern CAddInModule _AtlModule; // CConnect STDMETHODIMP CConnect::OnConnection(IDispatch *pApplication, ext_ConnectMode ConnectMode, IDispatch *pAddInInst, SAFEARRAY ** /*custom*/ ) { HRESULT hr = S_OK; pApplication->QueryInterface(__uuidof(DTE2), (LPVOID*)&m_pDTE); pAddInInst->QueryInterface(__uuidof(AddIn), (LPVOID*)&m_pAddInInstance); <%BEGIN VSCommand%>if(ConnectMode == 5) //5 == ext_cm_UISetup { HRESULT hr = S_OK; CComPtr pDisp; CComQIPtr pCommands; CComQIPtr pCommands2; CComQIPtr<_CommandBars> pCommandBars; CComPtr pCommandBarControl; CComPtr pCreatedCommand; CComPtr pMenuBarCommandBar; CComPtr pMenuBarControls; CComPtr pToolsCommandBarControl; CComQIPtr pToolsCommandBar; CComQIPtr pToolsPopup; IfFailGoCheck(m_pDTE->get_Commands(&pCommands), pCommands); pCommands2 = pCommands; if(SUCCEEDED(pCommands2->AddNamedCommand2(m_pAddInInstance, CComBSTR("<%=SAFEOBJNAME%>"), CComBSTR("<%=SAFEOBJNAME%>"), CComBSTR("Executes the command for <%=SAFEOBJNAME%>"), VARIANT_TRUE, CComVariant(59), NULL, vsCommandStatusSupported+vsCommandStatusEnabled, vsCommandStylePictAndText, vsCommandControlTypeButton, &pCreatedCommand)) && (pCreatedCommand)) { //Add a button to the tools menu bar. IfFailGoCheck(m_pDTE->get_CommandBars(&pDisp), pDisp); pCommandBars = pDisp; //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items: IfFailGoCheck(pCommandBars->get_Item(CComVariant(L"MenuBar"), &pMenuBarCommandBar), pMenuBarCommandBar); IfFailGoCheck(pMenuBarCommandBar->get_Controls(&pMenuBarControls), pMenuBarControls); //Find the Tools command bar on the MenuBar command bar: IfFailGoCheck(pMenuBarControls->get_Item(CComVariant(L"Tools"), &pToolsCommandBarControl), pToolsCommandBarControl); pToolsPopup = pToolsCommandBarControl; IfFailGoCheck(pToolsPopup->get_CommandBar(&pToolsCommandBar), pToolsCommandBar); //Add the control: pDisp = NULL; IfFailGoCheck(pCreatedCommand->AddControl(pToolsCommandBar, 1, &pDisp), pDisp); } return S_OK; } Error:<%END VSCommand%> return hr; } STDMETHODIMP CConnect::OnDisconnection(ext_DisconnectMode /*RemoveMode*/, SAFEARRAY ** /*custom*/ ) { m_pDTE = NULL; m_pAddInInstance = NULL; return S_OK; } STDMETHODIMP CConnect::OnAddInsUpdate (SAFEARRAY ** /*custom*/ ) { return S_OK; } STDMETHODIMP CConnect::OnStartupComplete (SAFEARRAY ** /*custom*/ ) { return S_OK; } STDMETHODIMP CConnect::OnBeginShutdown (SAFEARRAY ** /*custom*/ ) { return S_OK; } <%BEGIN VSCommand%>STDMETHODIMP CConnect::QueryStatus(BSTR bstrCmdName, vsCommandStatusTextWanted NeededText, vsCommandStatus *pStatusOption, VARIANT *pvarCommandText) { if(NeededText == vsCommandStatusTextWantedNone) { if(!_wcsicmp(bstrCmdName, L"<%=SAFEOBJNAME%>.Connect.<%=SAFEOBJNAME%>")) { *pStatusOption = (vsCommandStatus)(vsCommandStatusEnabled+vsCommandStatusSupported); } } return S_OK; } STDMETHODIMP CConnect::Exec(BSTR bstrCmdName, vsCommandExecOption ExecuteOption, VARIANT * /*pvarVariantIn*/, VARIANT * /*pvarVariantOut*/, VARIANT_BOOL *pvbHandled) { *pvbHandled = VARIANT_FALSE; if(ExecuteOption == vsCommandExecOptionDoDefault) { if(!_wcsicmp(bstrCmdName, L"<%=SAFEOBJNAME%>.Connect.<%=SAFEOBJNAME%>")) { *pvbHandled = VARIANT_TRUE; return S_OK; } } return S_OK; }<%END VSCommand%>