Microsoft 9GD00001 Computer Accessories User Manual


 
390 Microsoft Visual Studio 2010: A Beginner’s Guide
true, 59, ref contextGUIDS,
(int)vsCommandStatus
.vsCommandStatusSupported+
(int)vsCommandStatus.vsCommandStatusEnabled,
(int)vsCommandStyle
.vsCommandStylePictAndText,
vsCommandControlType
.vsCommandControlTypeButton);
VB:
Dim command As Command =
commands.AddNamedCommand2(
_addInInstance, "KeystrokeFinderVB",
"KeystrokeFinderVB",
"Executes the command for KeystrokeFinderVB",
True, 59, Nothing,
CType(vsCommandStatus.vsCommandStatusSupported,
Integer) +
CType(vsCommandStatus.vsCommandStatusEnabled,
Integer),
vsCommandStyle.vsCommandStylePictAndText,
vsCommandControlType.vsCommandControlTypeButton)
AddNamedCommand2 returned a Command object, command, which must be placed
into VS somewhere so that a user can click it to invoke the Add-In. The next statement
accomplishes this task by adding command to the Tools menu. As you may recall from
previous examples, the code searched for and obtained a reference to the Tools menu. After
ensuring that both the command and toolsPopup refer to valid objects (a best practice), the
following code places command into the first position (at the top) of the Tools menu:
C#:
if((command != null) &&
(toolsPopup != null))
{
command.AddControl(
toolsPopup.CommandBar, 1);
}
VB:
command.AddControl(toolsPopup.CommandBar, 1)
This completes the responsibilities of the OnConnection method. If you had your own
code for initializing the Add-In, the OnConnection method would be a good place to put
it. The preceding example was useful because now you know how to access VS menus
and commands. The example also demonstrated the importance of the main application
object and how it’s used as the starting point for getting to other part of VS.