388Microsoft Visual Studio 2010: A Beginner’s Guide
ext_ConnectMode.ext_cm_UISetup, as shown in the following code. The remaining code in the OnConnection method will only execute if the following condition is true:
C#:
if(connectMode == ext_ConnectMode.ext_cm_UISetup)
VB:
If connectMode = ext_ConnectMode.ext_cm_UISetup Then
The first time the code runs, the code within the preceding if statement will execute, creating a menu item for the KeystrokeFinder
The following code uses _applicationObject to get a list of commands, which is a list of all the actions you can take with VS. As discussed earlier, _applicationObject is type DTE2 and serves as the parent object for accessing all functionality in VS.
C#:
Commands2 commands = (Commands2)_applicationObject.Commands;
VB:
Dim commands As Commands2 =
CType(_applicationObject.Commands, Commands2)
In the VS automation object model, a menu item is called a CommandBar. So, you get a reference to a CommandBars collection, again through _applicationObject, to reference the MenuBar, which is the main VS menu, assigned to menuBarCommandBar:
C#:
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((
Microsoft.VisualStudio.CommandBars.CommandBars) _applicationObject.CommandBars)["MenuBar"];
VB:
Dim commandBars As CommandBars = CType(_applicationObject.CommandBars, CommandBars)
Dim menuBarCommandBar As CommandBar = commandBars.Item("MenuBar")