Share via


Commands.AddCommandBar(String, vsCommandBarType, Object, Int32) Method

Definition

Creates a command bar that is saved and available the next time the environment is started.

winrt::Windows::Foundation::IInspectable AddCommandBar(std::wstring const & Name, EnvDTE::vsCommandBarType Type, winrt::Windows::Foundation::IInspectable const & CommandBarParent, int Position = 1);
[System.Runtime.InteropServices.DispId(12)]
public object AddCommandBar (string Name, EnvDTE.vsCommandBarType Type, object CommandBarParent, int Position = 1);
[<System.Runtime.InteropServices.DispId(12)>]
abstract member AddCommandBar : string * EnvDTE.vsCommandBarType * obj * int -> obj
Public Function AddCommandBar (Name As String, Type As vsCommandBarType, Optional CommandBarParent As Object, Optional Position As Integer = 1) As Object

Parameters

Name
String

Required. A name for the new command bar.

Type
vsCommandBarType

Required. A vsCommandBarType constant that determines the type of command bar:

CommandBarParent
Object

Optional. An Office CommandBar object to which the new command bar is to be added. (This is required, however, if Type is vsCommandBarTypeMenu.)

Position
Int32

Optional. The index position, starting at one, in the command bar to place the new command bar.

Returns

A CommandBar object.

Attributes

Remarks

The CommandBar object is a member of the Microsoft Office object model.

The command bar added with this method is a permanent command bar, which is available in every session of the IDE whether or not the VSPackage is loaded. You should use this method to add a command bar only if you want a permanent command bar. You should call this method only once, when your VSPackage is loaded for the first time. If you want a temporary command bar, which appears only when the VSPackage is actually loaded, you must use the DTE.CommandBars.Add method when you load the VSPackage, and then call DTE.CommandBars.Remove method when it is unloaded.

Since a permanent command bar appears even when the VSPackage is not loaded, you should be sure to remove it when the VSPackage is uninstalled. Therefore, you must use an MSI to install and uninstall your VSPackage, and add a custom action to your uninstall program.

For more information about menus and commands, see Commands, Menus, and Toolbars.

Applies to