简体   繁体   中英

How to add a button in Menu Bar and Context Menu

I have to make an "Generic Search Engine" extension for Visual Studio. I know that the Add-in extension is not compatible with VS 2013, but I've found information on how to change it to VSPackage.

Every thing that I know until now is thanks to the book "Visual-Studio-Add-Ins-Succinctly"

The problem is that I have to write the extension in C++ and the documentation is very little. This is also my first real project so I don't know to much about Add-in and VSPackage.

The first steps propose by my mentor are:

  • adding a button to the "Menu Bar", next to File, Edit, View, Tools ...
  • adding a button to the "Context Menu", next to Cut, Copy, Paste
  • opening a new tab( window ) when one of the buttons are clicked

I've found the code that adds the button in the Tools Bar ( it was generated automatically )

        String ^toolsMenuName = "Tools";

        _CommandBars ^commandBars = dynamic_cast<CommandBars^>(_applicationObject->CommandBars);
        CommandBar ^menuBarCommandBar = dynamic_cast<CommandBar^>(commandBars["MenuBar"]);

        CommandBarControl ^toolsControl = menuBarCommandBar->Controls[toolsMenuName];
        CommandBarPopup ^toolsPopup = dynamic_cast<CommandBarPopup^>(toolsControl);

        try
        {   
            Command ^command = commands->AddNamedCommand2(_addInInstance, "MyAddin", "MyAddin", "Executes the command for MyAddin", true, 69, contextGUIDs, (int)vsCommandStatus::vsCommandStatusSupported+(int)vsCommandStatus::vsCommandStatusEnabled, (int)vsCommandStyle::vsCommandStylePictAndText, vsCommandControlType::vsCommandControlTypeButton);

            if((command) && (toolsPopup))
            {
                command->AddControl(toolsPopup->CommandBar, 1);
            }
        }
        catch(System::ArgumentException ^){}

But I can't find anywhere information about how to change the location of the add-in button or add it in the Context Menu.

Also I don't know how that new tab( window ) is called. I don't think that at this step is important what that tab( window ) will do, I just have to open it for now.

It will be of great help if somebody can help me with this problem.

I'm willing to start again with VSPackage if somebody can tell me a good book or website that presents many problems, written in C++ language.

VS package/extension is the way to go, definitely not an add-in as it is deprecated. I don't think much is written about extensibility in C++, but you should not have problems converting from C#. For samples and tutorials I recommend the Visual Studio Extensibility (VSX) site by Carlos Quintero.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM