CreateToolWindow2

Does anyone have any code examples (C#) on how to use CreateToolWindow2 method

Answer this question

CreateToolWindow2

  • pstavroulis

    thanks, that worked.

    Now, i'm getting a weird error when debuggin the project, and I open tool window thru Tools menu (with some basic user control in it), when I close VS, I get:

    System.Runtime.InteropServices.ExternalException was unhandled
      Message="External exception"
      Source="System.Windows.Forms"
      ErrorCode=-2147467263
      StackTrace:
           at System.Windows.Forms.Control.ActiveXImpl.ThrowHr(Int32 hr)

           at System.Windows.Forms.Control.ActiveXImpl.DoVerb(Int32 iVerb, IntPtr lpmsg, IOleClientSite pActiveSite, Int32 lindex, IntPtr hwndParent, COMRECT lprcPosRect)

           at System.Windows.Forms.Control.System.Windows.Forms.UnsafeNativeMethods.IOleObject.DoVerb(Int32 iVerb, IntPtr lpmsg, IOleClientSite pActiveSite, Int32 lindex, IntPtr hwndParent, COMRECT lprcPosRect)

    It doesn't matter if I still have the tool window open, or closed, it always throws this error. When I do not open the tool window, and close VS, there is no error.


  • Jav74411

    I'm suffering from this exception too. Have you, Werdna, or someone else found a solution since

    Regards,
    Thomas

  • Robert McArthur

    Here is a C# sample of CreateToolWindow2.   I created my toolwindow in a C# add-in.  You could paste the code in the OnConnection method for a C# add-in for VS.  Hope you find it helpful.  


    EnvDTE80.DTE2 dte2obj;

    EnvDTE80.Windows2 wins2obj;

    AddIn addinobj;

    object ctlobj=null;

    Window newwinobj;

    _applicationObject = (DTE2)application; //application is a parameter passed in to the OnConnection method

    _addInInstance = (AddIn)addInInst; //addInInst is a parameter passed in to the OnConnection method

    dte2obj= _applicationObject;

    //a toolwindow needs to be connected to an add-in. In this sample code, I've just used one of the add-ins created

    addinobj = dte2obj.AddIns.Item(1);

    wins2obj = (Windows2)dte2obj.Windows;

    //Create a windows control that you would want to host inside the tool window, provide the path, class name, a unique guid, caption for the toolwindow

    //for the control

    string assemblypath = "d:\\temp\\CreateHelloWorldToolWindow.dll";

    string classname = "CreateHelloWorldToolWindow.UserControl1";

    string guidpos = "{426E8D27-3D33-4fc8-B3E9-9883AADC679F}";

    string caption = "CreateToolWindow2 Test";

    newwinobj = wins2obj.CreateToolWindow2(addinobj, assemblypath, classname, caption, guidpos, ref ctlobj);

    newwinobj.Visible = true;



  • hrlevy

    Sorry to bring this up again...

    I want to create a toolwindow and place a usercontrol in it. So far, the CreateToolWindow2 method would work, if I want visual Studio to create the usercontrol (I think it uses reflection). But in my case, I already have the usercontrol instance and I just want to pass e.g. the reference to the toolwindow method.

    How does that work !

    And another question: The GuidPosition parameter in the CreateToolWindow2 , what's that for ! Is that for Visual Studio to remember the position of the toolwindow !

    Any help is appreciated!

    Regards

  • cmille19

    BTW, ErrorCode = -2147467263 = 0x80004001 = "Not implemented"
  • CreateToolWindow2