Using the DTE to customize VSTA IDE menus

 

Using the DTE, you can customize the UI and user interaction of the VSTA IDE. 

 

Here's a quick snippet that shows how to add a ‘La&unch Something’ menu button to the Tools menu of the VSTA IDE. 

 

CustomizeIDEMenu() is a method in the host application that assumes that VSTA is initialized and a valid reference to the DTE is provided.

 

using

 

 

 

Microsoft.VisualStudio.CommandBars;

        public void CustomizeIDEMenu()

        {

 

 

            Object objMissing = System.Reflection.Missing.Value;

 

            DTE dte = mProgram.mVSTAHookup.DesignTimeEnvironment;

            CommandBars commandBars = dte.CommandBars as CommandBars;

            CommandBarControl control = commandBars["Tools"].Controls.Add(MsoControlType.msoControlButton,

                                                                           1, objMissing, objMissing, true);

            btnLaunchSomething = control as CommandBarButton;

            btnLaunchSomething.Caption = "La&unch Something";

            //btnLaunchSomething.FaceId

            btnLaunchSomething.Click += new _CommandBarButtonEvents_ClickEventHandler(btnLaunchSomething_Click);

        }

 

void btnLaunchSomething_Click(CommandBarButton Ctrl, ref bool CancelDefault)

        {

            WriteLine("Launch Something!");

        }

 

 You can find more information about programming the DTE from the Visual Studio Extensibility forum


Posted Mar 15 2007, 06:48 PM by Gary
Copyright Summit Software Company, 2008. All rights reserved.