Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 13: Extending Visual Studio 2010 387
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)
command.AddControl(toolsPopup.CommandBar, 1)
Catch argumentException As System.ArgumentException
End Try
End If
End Sub
Dissecting Listing 13-2 into its constituent parts demonstrates the role OnConnection
has and how it affects subsequent code. The first part of the method obtains references to a
couple of important objects: application and addInInst. The following excerpt shows how
to obtain a reference to these objects and convert them to DTE2 and AddIn, respectively.
The references to _applicationObject and _addInInstance are fields of the Connect class,
which is important because now other methods of the class will be able to access these
objects.
C#:
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
VB:
_applicationObject = CType(application, DTE2)
_addInInstance = CType(addInInst, AddIn)
The remaining code in OnConnection sets up the menu item under the Tools menu,
as directed by choosing to build a command UI, shown in Figure 13-5. However, this
only occurs one time—the first time the application runs. To make sure the menu item
sets up one time, the code checks the connectMode parameter to see if it’s set to