// This is the main DLL file. #include "stdafx.h" #include "Connect.h" void <%=SAFEOBJNAME%>::Connect::OnAddInsUpdate(System::Array ^%custom) { } void <%=SAFEOBJNAME%>::Connect::OnBeginShutdown(System::Array ^%custom) { } void <%=SAFEOBJNAME%>::Connect::OnConnection(System::Object ^Application, ext_ConnectMode ConnectMode, System::Object ^AddInInst, System::Array ^%custom) { _applicationObject = dynamic_cast(Application); _addInInstance = dynamic_cast(AddInInst); <%BEGIN VSCommand%>if(ConnectMode == ext_ConnectMode::ext_cm_UISetup) { array< Object^ >^ contextGUIDs = gcnew array< Object^ >(0); Commands2 ^commands = dynamic_cast(_applicationObject->Commands); String ^toolsMenuName; try { //If you would like to move the command to a different menu, change the word "Tools" to the // English version of the menu. This code will take the culture, append on the name of the menu // then add the command to that menu. You can find a list of all the top-level menus in the file // CommandBar.resx. ResourceManager ^resourceManager = gcnew ResourceManager("<%=SAFEOBJNAME%>.CommandBar", Assembly::GetExecutingAssembly()); CultureInfo ^cultureInfo = gcnew System::Globalization::CultureInfo(_applicationObject->LocaleID); toolsMenuName = resourceManager->GetString(String::Concat(cultureInfo->TwoLetterISOLanguageName, "Tools")); } catch(...) { //We tried to find a localized version of the word Tools, but one was not found. // Default to the en-US word, which may work for the current culture. toolsMenuName = "Tools"; } //Place the command on the tools menu. //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items: _CommandBars ^commandBars = dynamic_cast(_applicationObject->CommandBars); CommandBar ^menuBarCommandBar = dynamic_cast(commandBars["MenuBar"]); //Find the Tools command bar on the MenuBar command bar: CommandBarControl ^toolsControl = menuBarCommandBar->Controls[toolsMenuName]; CommandBarPopup ^toolsPopup = dynamic_cast(toolsControl); //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in, // just make sure you also update the QueryStatus/Exec method to include the new command names. try { //Add a command to the Commands collection: Command ^command = commands->AddNamedCommand2(_addInInstance, "<%=SAFEOBJNAME%>", "<%=SAFEOBJNAME%>", "Executes the command for <%=SAFEOBJNAME%>", true, 59, contextGUIDs, (int)vsCommandStatus::vsCommandStatusSupported+(int)vsCommandStatus::vsCommandStatusEnabled, (int)vsCommandStyle::vsCommandStylePictAndText, vsCommandControlType::vsCommandControlTypeButton); //Add a control for the command to the tools menu: if((command) && (toolsPopup)) { command->AddControl(toolsPopup->CommandBar, 1); } } catch(System::ArgumentException ^argumentException) { //If we are here, then the exception is probably because a command with that name // already exists. If so there is no need to recreate the command and we can // safely ignore the exception. } }<%END VSCommand%> } void <%=SAFEOBJNAME%>::Connect::OnStartupComplete(System::Array ^%custom) { } void <%=SAFEOBJNAME%>::Connect::OnDisconnection(ext_DisconnectMode removeMode, System::Array ^%custom) { } <%BEGIN VSCommand%> void <%=SAFEOBJNAME%>::Connect::Exec(String ^CmdName, vsCommandExecOption ExecuteOption, Object ^%VariantIn, Object ^%VariantOut, bool %handled) { handled = false; if(ExecuteOption == vsCommandExecOption::vsCommandExecOptionDoDefault) { if(!CmdName->CompareTo("<%=SAFEOBJNAME%>.Connect.<%=SAFEOBJNAME%>")) { handled = true; return; } } } void <%=SAFEOBJNAME%>::Connect::QueryStatus(String ^CmdName, vsCommandStatusTextWanted NeededText, vsCommandStatus %StatusOption, Object ^%CommandText) { if(NeededText == vsCommandStatusTextWanted::vsCommandStatusTextWantedNone) { if(!CmdName->CompareTo("<%=SAFEOBJNAME%>.Connect.<%=SAFEOBJNAME%>")) { StatusOption = (vsCommandStatus)(vsCommandStatus::vsCommandStatusSupported+vsCommandStatus::vsCommandStatusEnabled); return; } } }<%END VSCommand%>