HOWTO: Getting the "View" command bar of Visual Studio .NET from an add-in

Article translations Article translations
Article ID: 555186 - View products that this article applies to.
Author: Carlos Quintero MVP
Expand all | Collapse all

SUMMARY

This article describes how to get the "View" command bar of the main menu of Visual Studio .NET in order to add new entries to it from an add-in.

SYMPTOMS

This article describes how to get the "View" command bar of the main menu of Visual Studio .NET in order to add new entries to it from an add-in, since DTE.CommandBars.Item("View") returns a different command bar.

MORE INFORMATION

In order to retrieve the "View" command bar of the main menu of Visual Studio .NET, you have to iterate through the controls of the "MenuBar" command bar, casting them to a command bar popup and checking its name. The following VB.NET add-in snippet shows the technique:
 
   Private m_objDTE As EnvDTE.DTE
 
   Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, _
      ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
 
      Dim objMenuBarCommandBar As CommandBar
      Dim objViewCommandBar As CommandBar
      Dim objCommandBarControl As CommandBarControl
      Dim objCommandBarPopup As CommandBarPopup
      Dim sControlList As String
 
      m_objDTE = DirectCast(application, EnvDTE.DTE)
 
      Try
 
         objMenuBarCommandBar = m_objDTE.CommandBars.Item("MenuBar")
 
         For Each objCommandBarControl In objMenuBarCommandBar.Controls

            If objCommandBarControl.Type = MsoControlType.msoControlPopup Then

               objCommandBarPopup = DirectCast(objCommandBarControl, CommandBarPopup)

               If objCommandBarPopup.CommandBar.Name = "View" Then

                  objViewCommandBar = objCommandBarPopup.CommandBar

                  Exit For

               End If

            End If

         Next
 
         sControlList = "Controls currently visible on the View CommandBar: " & Microsoft.VisualBasic.ControlChars.CrLf

         For Each objCommandBarControl In objViewCommandBar.Controls

            If objCommandBarControl.Visible Then

               sControlList &= Microsoft.VisualBasic.ControlChars.CrLf & objCommandBarControl.Caption

            End If

         Next

         System.Windows.Forms.MessageBox.Show(sControlList)
 
      Catch objException As System.Exception
 
         System.Windows.Forms.MessageBox.Show(objException.ToString)

      End Try
 
   End Sub
 

Properties

Article ID: 555186 - Last Review: August 27, 2004 - Revision: 1.0
APPLIES TO
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2002 Academic Edition
  • Microsoft Visual Studio .NET 2002 Enterprise Developer
  • Microsoft Visual Studio .NET 2002 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Professional Edition
Keywords: 
kbpubmvp kbpubtypecca kbhowto KB555186
COMMUNITY SOLUTIONS CONTENT DISCLAIMER
MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com