I've created a custom output window pane for my VSPackage
:
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?
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();
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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.