How to: Create Toolbars on the IDE

注意

Beginning with Visual Studio 2008 SDK, use XML Command Table (.vsct) files instead of command table configuration (.ctc) files to define how menus and commands appear in your VSPackages. For more information, see XML-Based Command Table Configuration (.vsct) Files.

A VSPackage adds a toolbar to the IDE by defining a menu item of type Toolbar in the MENUS_BEGIN – MENUS_END section of a Command Table Configuration (.Ctc) Files.

A toolbar has the following features:

  • A toolbar is a horizontal or vertical bar that contains buttons which are either an icon, text, or a combination of icon and text.

  • A toolbar can be docked on any edge of its parent window.

  • The Visual Studio integrated development environment (IDE) treats VSPackage-contributed toolbars just like all other toolbars owned by the IDE. Therefore, a VSPackage does not have to take any action to have its own toolbars customized through the Customize dialog box (available by selecting Customize from the Tools menu). Any changes the user might make to a VSPackage toolbar is automatically tracked and handled by the IDE.

  • The IDE automatically handles making toolbars visible or hidden from the Toolbars submenu of the View menu.

  • A toolbar with no visible command is automatically hidden.

All of these features can be changed using flags that are specified when the toolbar is defined in the .ctc file as discussed in the following procedure.

The following walkthroughs show how to create toolbars in both managed (Visual C#) and unmanaged (Visual C++) code:

To create a toolbar on the IDE

  1. Select a GUID:ID pair to represent the new toolbar. The ctc.exe compiler expects a GUID data type in this format:

    #define guidCmd  { 0xBC8DA515, 0x5743, 0x4FEB, { 0xA9, 0x29, 0x29, 0x38, 0x24, 0x9C, 0xBA, 0x26 } }
    

    The pair definition continues with a colon and finally a unique number. In a typical VSPackage, a single GUID is created for all commands, menus, and toolbars. Since all such elements are identified by a GUID:ID pair, all of the commands, menus and toolbars are distinguished from each other by the ID portion of the GUID:ID pair.

  2. Create a new line in the MENUS_BEGIN – MENUS_END section of the command table (.ctc) file. For more information, see MENUS_BEGIN – MENUS_END. A toolbar is essentially a menu and it is defined in the .ctc file the same way as a menu with the exception of the type flags.

    • Set the Menu ID field to the GUID:ID of the new toolbar as created in step 1.

    • Set the Group ID field to the same GUID:ID used in the Menu ID field.

      Menus of type Toolbarare always placed directly on the IDE, and therefore the Group ID field is always ignored. By convention, the toolbar's GUID:ID pair specified in the Menu ID field is also used in the Group ID field.

      注意

      Toolbar menus should not be used as submenus of other menus.

    • Set the Priority field to 0.

      The Priority field is not used by toolbars in the IDE, and this value is therefore ignored. By convention, the Priority field is set to 0 when it is not used.

    • Set the Type field to Toolbar. As appropriate, add the following flags to the Type field, using the | (logical OR) operator:

      DefaultDocked – if you want the toolbar to be docked to the IDE by default. Otherwise, the toolbar is initially floating above all windows.

      NoToolbarClose - if you do not want the VSPackage user to be able to close or hide the toolbar. Use this flag carefully as the user should be allowed to affect all toolbars in the IDE.

      NotInTBList – if you do not want the toolbar to appear in the list of available toolbars. That is, the toolbar does not appear in the Toolbar submenu of the View menu and therefore the user cannot make the toolbar visible or hidden except through the Customize dialog box available from the Tools menu. Use this flag carefully as the user should be allowed to easily affect all toolbars in the IDE.

      AlwaysCreate – if you want to create the toolbar even if it contains no commands.

      TextChanges – if you want to associate dynamic text (ToolTips) with the toolbar.

    • Set the Menu Name field to the name of the toolbar, enclosed in quotes.

      注意

      The value of the Menu Name field appears as the name of the toolbar in the Customize dialog box if the Menu Text field is not specified.

    • Set the Menu Text field to the name, in quotes, of the toolbar as it is to appear in the Customize dialog box and Toolbars submenu of the View menu.

  3. Create a new group to contain the commands that are to appear on your toolbar.

    See the NEWGROUPS_BEGIN – NEWGROUPS_END section for details on creating new groups.

    Set the parent for this new group to be the GUID:ID of the toolbar you created in step 2. This places the group of commands on the toolbar.

  4. Add commands to the toolbar by creating command entries in the BUTTONS_BEGIN – BUTTONS_END section of the .ctc file and setting the Group ID field for each command to the GUID:ID of the group created in step 3.

    Use the Priority field of each command entry to specify the order in which the commands appear in the group.

  5. Using the command table compiler (ctc.exe), convert your .ctc file to a binary resource that can be included in your VSPackage satellite dll file. For information on the Command Table Compiler, see How to: Create Menu Commands for a VSPackage By Using the Binary Command Table Compiler.

See Also

Concepts

Common Menu Tasks

Designing Command Table Configuration Files

CMDPLACEMENT_SECTION – CMDPLACEMENT_END