This documentation is archived and is not being maintained.

Walkthrough: Adding a Toolbar to the IDE

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This walkthrough guides you through the steps of adding a toolbar to the Visual Studio integrated development environment (IDE).

A toolbar is a small, horizontal or vertical window that contains buttons bound to commands. Depending on its implementation, a toolbar in the IDE can be repositioned, docked on any side of the IDE, or made to stay in front of all other windows.

In addition, commands can be added to or removed from a toolbar through the Customize dialog box. The toolbar supplied by a VSPackage typically is a default toolbar that the user can customize. The IDE handles all customization, while the VSPackage only needs to respond to commands. The VSPackage does not need to know where a command is physically located.

For more information on menus and their related .ctc files, see Menus and Toolbars.

This walkthrough requires the Visual Studio Industry Partner (VSIP) SDK to be installed.

This section demonstrates how to use the Visual Studio Integration Package wizard to create a VSPackage that supports a single menu command. The information is written to the experimental registry hive for Visual Studio.

To create the MyToolbarPackage VSPackage

  1. Open Visual Studio. On the File menu, point to New, and the click Project.

  2. In the Project types pane of the New Project dialog box, expand the Other Project Types node, and then click Extensibility.

  3. In the Templates pane, select Visual Studio Integration Package.

  4. In the Name box, type MyToolbarPackage. Select a destination folder for the project.

  5. Click OK to open the Visual Studio Integration Package Wizard.

  6. Read the Welcome to the Visual Studio Integration Package Wizard page.

  7. On the Select a Programming Language page, select Visual C# and accept the default for the key file.

    You also can use the Visual C++ programming language for your VSPackage. The steps in this walkthrough work for both languages.

  8. On the Basic VSPackage Information page, accept the defaults.

  9. On the Select VSPackage Options page, select the Menu Command check box.

  10. On the Command Options page, set the Command Name to My Toolbar Test Command and set the Command ID to cmdidMyTestCmd.

  11. Click Finish. After the wizard finishes building the project, the status bar displays that the MyToolbarPackage solution has built successfully.

To create a toolbar for the IDE

  1. In Solution Explorer, expand the CtcComponents folder and right-click the CommandIds.h file, and then click Open to open it in a text editor.

  2. In the Menu IDs section, add a definition for MyToolbar:

    #define MyToolbar 0x1000
    
  3. In the Menu Group IDs section, add a definition for MyToolbarGroup:

    #define MyToolbarGroup 0x1050
    
  4. In Solution Explorer, right-click the MyToolbarPackage.ctc file, and then click Open to open it in a text editor.

  5. In the MENUS_BEGIN section, add the following lines to define the toolbar:

    guidMyToolbarPackageCmdSet:MyToolbar,     // Menu ID
        guidMyToolbarPackageCmdSet:MyToolbar, // Parent Group
        0x0000,                               // Priority
        TOOLBAR | DEFAULTDOCKED,              // Type and Flags
        "My IDE Toolbar";                     // Toolbar Name
    

    Toolbars cannot be nested like submenus, so the parent group of a toolbar is, by convention, set to the same GUID:ID pair as the toolbar itself. Typically, initial placement of a toolbar is defined programmatically, but thereafter, changes by the user are persisted.

  6. In the NEWGROUPS_BEGIN section, after the existing group entry, add the following lines to define the group that contains the commands for the toolbar:

    // Any command added to this group appears on the toolbar.
    guidMyToolbarPackageCmdSet:MyToolbarGroup, // Group ID
        guidMyToolbarPackageCmdSet:MyToolbar,  // Menu ID
        0x0000;                                // Priority
    
  7. In the CMDPLACEMENT_SECTION section, type the following lines to add the existing command to the toolbar group so the toolbar will be displayed (by default, if a toolbar has no commands, it does not appear):

    guidMyToolbarPackageCmdSet:cmdidMyTestCmd,     // Command ID
        guidMyToolbarPackageCmdSet:MyToolbarGroup, // Parent ID
        0x0000;                                    // Priority
    
  8. Save the project, then on the Build menu, click Build Solution. Correct any errors that might arise.

  9. Open an instance of the experimental Visual Studio by pressing F5 or selecting Start on the Debug menu. This runs the experimental Visual Studio under the debugger and allows debugging of your VSPackage.

  10. Right-click the IDE menu bar, and then select My IDE Toolbar from the list of toolbars.

  11. Click the icon on the new toolbar to see a dialog box with the message "Inside Company.MyToolbarPackage.MyToolbarPackage.MenuItemCallback()".

Show: