5

I've created a custom output window pane for my VSPackage:

Output window and tabs in Visual Studio 2013

Using this code:

// Creating Output Window for our package.
IVsOutputWindow output = GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
Guid guildGeneral = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.GeneralPane_guid;
int hr = output.CreatePane(guildGeneral, "Codex", 1, 0);
hr = output.GetPane(guildGeneral, out ApplicationConstants.pane);

ApplicationConstants.pane.Activate();

QUESTION

How can I select the Output tab when other tabs are currently selected?

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128

2 Answers2

5

To activate (focus) on Visual Studio's Output window:

DTE dte = (DTE)GetService(typeof(DTE));
Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
window.Activate();
A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
  • @UsRGk Add `Microsoft.VisualStudio.Shell` to your references. See here: https://msdn.microsoft.com/en-us/library/bb138962.aspx – A-Sharabiani Dec 06 '16 at 06:06
0

This is my version, updated to VS2019

    class GetOutputPanel
    {
        private int retries;
        public IVsOutputWindowPane pane;

        void writeToOutputPanel(string txt)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            pane.OutputString(txt);
        }
        void getOutputPanel(AsyncPackage package, EnvDTE80.DTE2 dte2)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            EnvDTE.Window w = dte2.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
            w.Activate();
            var output_windows_opening_async = package.GetServiceAsync(typeof(SVsOutputWindow));
            Timer timer = new Timer();
            retries = 0;
            timer.Tick += (object sender, EventArgs e) => {
                ThreadHelper.ThrowIfNotOnUIThread();
                if (pane != null)
                {
                    (sender as Timer).Stop();
                    return;
                }
                if(!output_windows_opening_async.IsCompleted)
                {
                    if(retries++ > 10) (sender as Timer).Stop();
                    return;
                }

#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
                output_windows_opening_async.Wait();
                IVsOutputWindow output = (output_windows_opening_async.Result) as IVsOutputWindow;
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
                Guid guildGeneral = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.GeneralPane_guid;
                output.CreatePane(guildGeneral, "Ambar - DEMO Builder", 1, 0);
                output.GetPane(guildGeneral, out pane);
                pane.Activate();
                (sender as Timer).Stop();
            };
            timer.Interval = 1000;
            timer.Start();
        }
    }
Ing. Gerardo Sánchez
  • 1,607
  • 15
  • 14