Windows2.CreateToolWindow2(AddIn, String, String, String, String, Object) Method


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

 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);
public EnvDTE.Window CreateToolWindow2 (EnvDTE.AddIn Addin, string Assembly, string Class, string Caption, string GuidPosition, out object ControlObject);
abstract member CreateToolWindow2 : EnvDTE.AddIn * string * string * string * string * obj -> EnvDTE.Window



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


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


The full name of the class implementing the User control.


The caption to display in the new tool window.


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


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


A Window object.



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.


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;  


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