Share via


Creating Toolbar Buttons for Add-in Commands Programmatically

Home Page (Add-ins)OverviewHow Do I ... TopicsFAQReference

The user can carry out an add-in command by clicking a toolbar button assigned to the command. The user can create a button through the user interface, or you can create the button programmatically.

If you use the Developer Studio Add-in Wizard and select the Provides a toolbar option, the wizard automatically generates the code for the button. However, if you add more commands to the add-in, and you want buttons for these commands, you must add code for these buttons.

The following procedure describes how to add the code for a button.

To create a toolbar button programmatically

  1. Open the project for the add-in.

  2. In ClassView, expand the project's classes, and then expand the CDSAddIn class.

  3. Double-click the OnConnection method.

  4. Search for the code that adds the appropriate command. This code calls the AddCommand method.

  5. After the Addcommand call, call the AddCommandBarButton method if the bFirstTime parameter of the OnConnection method has a value of VARIANT_TRUE.

    This parameter directs Developer Studio to call AddCommandBarButton only when the user first connects the add-in to Developer Studio.

When the user removes an add-in from the Visual C++ environment, the add-in does not have to remove the toolbar buttons created because they are removed automatically.

Visual C++ provides other ways of using toolbar buttons to customize your desktop environment. For details, see Overview: Customizing Visual C++.

See Also   Assigning Key Sequences to Add-in Commands Visually, Creating Toolbar Buttons for Add-in Commands Visually