Wie erstelle ich ein echtes benutzerdefiniertes Ausgangsfenster?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie erstelle ich ein echtes benutzerdefiniertes Ausgangsfenster?

Post by Anonymous »

Ich möchte ein zusätzliches, benutzerdefiniertes Ausgabefenster für MSVC 2022 für einige erweiterte Anmeldezwecke erstellen. Ich habe diesen Artikel verfolgt und einen solchen Code implementiert: < /p>
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using System;
using System.ComponentModel.Design;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using Task = System.Threading.Tasks.Task;
using Microsoft.VisualStudio;

namespace VSIXProject9
{
///
/// Command handler
///
internal sealed class My_Output_Wnd_1
{
///
/// Command ID.
///
public const int CommandId = 0x0100;

///
/// Command menu group (command set GUID).
///
public static readonly Guid CommandSet = new Guid("e19c8dcd-4193-4104-b858-d3a7a29166c6");

///
/// VS Package that provides this command, not null.
///
private readonly AsyncPackage package;

///
/// Initializes a new instance of the class.
/// Adds our command handlers for menu (commands must exist in the command table file)
///
///
Owner package, not null.
/// Command service to add command to, not null.
private My_Output_Wnd_1(AsyncPackage package, OleMenuCommandService commandService)
{
this.package = package ?? throw new ArgumentNullException(nameof(package));
commandService = commandService ?? throw new ArgumentNullException(nameof(commandService));

var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(this.Execute, menuCommandID);
commandService.AddCommand(menuItem);

///////////////////////////////

IVsOutputWindow outWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;

// Use e.g. Tools -> Create GUID to make a stable, but unique GUID for your pane.
// Also, in a real project, this should probably be a static constant, and not a local variable
Guid customGuid = new Guid("0F44E2D1-F5FA-4d2d-AB30-22BE8ECD9789");
string customTitle = "Custom Window Title";
outWindow.CreatePane(ref customGuid, customTitle, 1, 1);

IVsOutputWindowPane customPane;
outWindow.GetPane(ref customGuid, out customPane);

customPane.OutputString("Hello, Custom World!");
customPane.Activate(); // Brings this pane into view
}

///
/// Gets the instance of the command.
///
public static My_Output_Wnd_1 Instance
{
get;
private set;
}

///
/// Gets the service provider from the owner package.
///
private Microsoft.VisualStudio.Shell.IAsyncServiceProvider ServiceProvider
{
get
{
return this.package;
}
}

///
/// Initializes the singleton instance of the command.
///
/// Owner package, not null.
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in My_Output_Wnd_1's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new My_Output_Wnd_1(package, commandService);
}

///
/// This function is the callback used to execute the command when the menu item is clicked.
/// See the constructor to see how the menu item is associated with this function using
/// OleMenuCommandService service and MenuCommand class.
///
/// Event sender.
/// Event args.
private void Execute(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);
string title = "My_Output_Wnd_1";

// Show a message box to prove we were here
VsShellUtilities.ShowMessageBox(
this.package,
message,
title,
OLEMSGICON.OLEMSGICON_INFO,
OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
}
}
}
< /code>
, aber definitiv nicht bekommen, was ich erwartet habe. Der Code hier erstellt kein zusätzliches, separates Ausgangsfenster, sondern erstellt nur sogenannte "Panel" für ein vorhandenes Ausgabefenster:

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post