
Automate Visual Studio #86
Chapter 12, Extending Visual Studio
|
385
HACK
the DTE.Commands.Item method. Here is an example of getting a reference to
this same command:
Dim com As Command = DTE.Commands.Item("Edit.FormatSelection")
Once you have the command object, you can add it to a command bar
(more commonly known as a toolbar)
[Hack #89] or even delete it if needed.
The
Commands object also includes an AddNewCommand method, which can be
used to add custom commands for an add-in.
Automate Windows
Visual Studio includes a large number of different windows. So many in fact
that there is a hack in this book dedicated to just knowing how to best man-
age all these windows
[Hack #16]. The Windows collection of the DTE object
allows you to access these windows and work with them. To get a reference
to a window, you will need to use one of the many
vsWindowKind constants.
There is a constant for each of the windows that can be shown in Visual Stu-
dio. Table 12-1 shows a list of some of the more common windows and
their corresponding
vsWindowKind constant.
Here is an example of creating a reference to a window:
Window win = env.Windows.Item(Constants.vsWindowKindToolbox);
Using the Window object, you can set normal window properties, such as
whether the window is visible or autohides, but more importantly, you can
sometimes access more functionality. The toolbox is a great example of this.
A Toolbox object can