/// <summary> /// Shows the tool window when the menu item is clicked. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event args.</param> private void ShowToolWindow(object sender, EventArgs e) { for (int i = 0; i < 10; i++) { /* * https://msdn.microsoft.com/en-us/library/cc512945.aspx * In the MIToolWindowCommand.cs file, find the ShowToolWindos() method.In this method, call the FindToolWindow method and set its create flag to false so that it will iterate through existing tool window instances until an available id is found. * To create a tool window instance, call the FindToolWindow method and set its id to an available value and its create flag to true. * By default, the value of the id parameter of the FindToolWindow method is 0.This makes a single - instance tool window.For more than one instance to be hosted, every instance must have its own unique id. * Call the Show method on the IVsWindowFrame object that is returned by the Frame property of the tool window instance. * By default, the ShowToolWindow method that is created by the tool window item template creates a single - instance tool window.The following example shows how to modify the ShowToolWindow method to create multiple instances. */ FirstToolWindow window = (FirstToolWindow)this.package.FindToolWindow(typeof(FirstToolWindow), i, false); if ((window == null) || (window.Frame == null)) { // Create the window with the first free ID. FirstToolWindow.id = i; window = (FirstToolWindow)this.package.FindToolWindow(typeof(FirstToolWindow), i, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException("Cannot create tool window"); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); break; } } }
private void ShowToolWindow(object sender, EventArgs e) { window = (FirstToolWindow)this.package.FindToolWindow(typeof(FirstToolWindow), 0, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException("Cannot create tool window"); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); //var mcs = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; //var toolbarbtnCmdID = new CommandID(new Guid(FirstToolWindowCommand.guidFirstToolWindowPackageCmdSet), FirstToolWindowCommand.cmdidWindowsMediaOpen); //var menuItem = new MenuCommand(new EventHandler(ButtonHandler), toolbarbtnCmdID); //mcs.AddCommand(menuItem); }