다음을 통해 공유


Windows2.CreateToolWindow2 Method

Definition

Caution

AddIn related extension points are no longer supported in Visual Studio.

Creates a new tool window and hosts a user-defined, .NET control in it.

public:
 EnvDTE::Window ^ CreateToolWindow2(EnvDTE::AddIn ^ Addin, System::String ^ Assembly, System::String ^ Class, System::String ^ Caption, System::String ^ GuidPosition, [Runtime::InteropServices::Out] System::Object ^ % ControlObject);
EnvDTE::Window CreateToolWindow2(EnvDTE::AddIn const & Addin, std::wstring const & Assembly, std::wstring const & Class, std::wstring const & Caption, std::wstring const & GuidPosition, [Runtime::InteropServices::Out] winrt::Windows::Foundation::IInspectable const & & ControlObject);
[System.Runtime.InteropServices.DispId(400)]
public EnvDTE.Window CreateToolWindow2 (EnvDTE.AddIn Addin, string Assembly, string Class, string Caption, string GuidPosition, out object ControlObject);
[System.Runtime.InteropServices.DispId(400)]
[System.Obsolete("AddIn related extension points are no longer supported in Visual Studio.")]
public EnvDTE.Window CreateToolWindow2 (EnvDTE.AddIn Addin, string Assembly, string Class, string Caption, string GuidPosition, out object ControlObject);
[<System.Runtime.InteropServices.DispId(400)>]
abstract member CreateToolWindow2 : EnvDTE.AddIn * string * string * string * string * obj -> EnvDTE.Window
[<System.Runtime.InteropServices.DispId(400)>]
[<System.Obsolete("AddIn related extension points are no longer supported in Visual Studio.")>]
abstract member CreateToolWindow2 : EnvDTE.AddIn * string * string * string * string * obj -> EnvDTE.Window
Public Function CreateToolWindow2 (Addin As AddIn, Assembly As String, Class As String, Caption As String, GuidPosition As String, ByRef ControlObject As Object) As Window

Parameters

Addin
AddIn

An instance of the add-in creating the tool window.

Assembly
String

The full name or file path of the assembly containing the User control.

Class
String

The full name of the class implementing the User control.

Caption
String

The caption to display in the new tool window.

GuidPosition
String

A unique identifier for the new window. (This can be used to locate the window in the Windows collection.)

ControlObject
Object

The User control to be hosted in the new tool window.

Returns

A Window object.

Attributes

Examples

The following example requires that you first create a User control by building a Windows Control Library project. Note the name of the control's project and class for use in the following code. Change the assemblypath string to the directory of the User control's DLL file. Also, the code is designed to replace the OnConnection method of an add-in project.

[C#]

public void OnConnection(object application, ext_ConnectMode   
  connectMode, object addInInst, ref Array custom)  
{  
    _applicationObject = (DTE2)application;  
    _addInInstance = (AddIn)addInInst;  
    EnvDTE80.Windows2 wins2obj;  
    AddIn addinobj;  
    object ctlobj = null;  
    Window newWinobj;  

    // A toolwindow must be connected to an add-in, so this line   
    // references one.  
    addinobj = _applicationObject.AddIns.Item(1);  
    wins2obj = (Windows2)_applicationObject.Windows;  

    // This section specifies the path and class name of the windows   
    // control that you want to host in the new tool window, as well as   
    // its caption and a unique GUID.  
    string assemblypath = "C:\\temp\\WindowsControlLibrary1.dll";  
    string classname = "WindowsControlLibrary1.UserControl1";  
    string guidpos = "{426E8D27-3D33-4FC8-B3E9-9883AADC679F}";  
    string caption = "CreateToolWindow2 Test";  

    // Create the new tool window and insert the user control in it.  
    newWinobj = wins2obj.CreateToolWindow2(addinobj, assemblypath,   
      classname, caption, guidpos, ref ctlobj);  
    newWinobj.Visible = true;  
}  

Remarks

Before invoking CreateToolWindow2 to create a new tool window, you should either move the User control (ControlObject) into the same assembly as the add-in, or set all of the attributes on the User control to make it fully visible to COM. (For example, checking the Register for COM interop option in the project's compile options.) If you do not do this, then the control will not marshal correctly and CreateToolWindow2 will return a null value.

If you attempt to set visibility states of the new tool window — such as height, width, or position — before the tool window is visible, you get an error. Make sure that the window is visible before attempting to set any such properties.

For information about creating ActiveX controls, see Creating an MFC ActiveX Control.

Applies to