locked
How can you make a new ToolWindow be docked at the same location as the VS StartPage? RRS feed

  • Question

  • I'm creating a new tool window in my VS addin, but no matter what I do, I can't seem to get it to dock with the Start Page.

     

    private Window2 CreateLeadtoolsControl(DTE2 applicationObject, AddIn addInInstance)
    {
      
    Windows2 windows = (Windows2)applicationObject.Windows;
      
    Window2 newToolWindow = null;
      
    string assemblypath = AssemblyFullPath;
      
    string classname = "MyDll.MyControl";
      
    string guidpos = "{806F3033-8463-4297-A26E-098B1D689742}";
      
    string caption = "MyAddIn Page";
      
    object ctlobj = null;
       newToolWindow = (
    Window2)windows.CreateToolWindow2(addInInstance, assemblypath, classname, caption, guidpos, ref ctlobj);
       newToolWindow.Linkable =
    true;
       newToolWindow.IsFloating =
    false;
    // //newToolWindow.WindowState = vsWindowState.vsWindowStateMaximize;
    // //newToolWindow.SetKind(vsWindowType.vsWindowTypeDocument);     crashes
    // Window2 frame = (Window2)windows.CreateLinkedWindowFrame(newToolWindow, newToolWindow, vsLinkedWindowType.vsLinkedWindowTypeTabbed);
    // frame.Height = 150;
    // frame.SetKind(EnvDTE.vsWindowType.vsWindowTypeToolWindow);
    // applicationObject.MainWindow.LinkedWindows.Add(frame);    crashes
    // frame.Activate();
    //}

    //applicationObject.MainWindow.LinkedWindows.Add(newToolWindow);  crashes

       newToolWindow.Visible =

    true;
       return newToolWindow;
    }

    Saturday, March 27, 2010 7:46 PM

Answers

  • It seems I don't need the call to LinkedWindows.Add.

    Setting the Linkable property to false is all it takes.

    Now it's working perfectly in VS 2005, 2008 & 2010!

    Thanks for your help!

    • Marked as answer by Ike Starnes Thursday, April 1, 2010 6:52 AM
    Thursday, April 1, 2010 6:52 AM

All replies

  • Hi Ike,

    Thanks for your post.

    I want to clarify with you what do you mean docking with the Start Page. If you mean you want to do custom tool window like Solution Explorer which could docking with Start Page, I think there is nothing wrong with your code. I have taken a test in my side, it works fine, the code as following shows:

    Windows2 wins = (EnvDTE80.Windows2)_applicationObject.Windows;
    Window2 frame = (EnvDTE80.Window2)wins.CreateLinkedWindowFrame(this.win, this.win, vsLinkedWindowType.vsLinkedWindowTypeTabbed);
    frame.SetKind(EnvDTE.vsWindowType.vsWindowTypeToolWindow);
    _applicationObject.MainWindow.LinkedWindows.Add(frame);
    this.win.Visible = true;
    

    There is a good MSDN example about linking window to other windows, please see:

    http://msdn.microsoft.com/en-us/library/envdte80.windows2(VS.80).aspx

    If I misunderstood you, or you have any comments, please feel free to let me know.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, March 29, 2010 7:43 AM
  • Yes, that's exactly what I mean.

    By the way, your code doesn't even compile for me.  There is no "this.win".

    And, if i change that to be the object returned by my call to CreateToolWindow2, then I get an exception:
    "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

    I'm using VS 2008 to build the AddIn, and I'm testing it in VS 2005, 2008, 2010.  It behaves differently in all 3, but none is the desired behavior.

    Also, can you point me to where in your code you are referencing / finding / linking to the Start Page?  I don't see anything in your code or the sample that you refered to that helps me with that.

    Related question: if the start page is not currently visible, then i want my new window to be maximized (i.e. the only tabbed window).

    If you actually have this working, then how about just posting the complete code?

    Monday, March 29, 2010 2:06 PM
  • Hi Ike,

    I suspect the exception is caused by CreateToolWindows2() function in your code. The third parameter in this function is the full name of the class implementing the User control. Does classname = "MyDll.MyControl"; is the full name of the class implementing the User Control? About how to create Visual Studio Tool Windows, please see:

    Creating Visual Studio Tool Windows

    About how to dock with start page, please refer to the code in my previous reply. And see the following picture whether it’s the result you want MediaPlayer1 Tool Window at the bottom is the custom Tool Window. 

     

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, March 30, 2010 2:17 AM
  • Try the following code.

    ToolWindowPane window = this.FindToolWindow(typeof(MyToolWindow), 0, true);
    if (null == window
       || null == window.Frame)
    {
    	throw new NotSupportedException(Resources.CanNotCreateWindow);
    }
    IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame as IVsWindowFrame;
    windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, VSFRAMEMODE.VSFM_MdiChild);
    Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());

    Note: I wrote the above code in a sample package, not in add in. Hence use something else instead "this.FindToolWindow(....)"


    Kiran Chand Palakkattiri
    [Life is not a personality contest]
    kiran.chand@live.in
    Tuesday, March 30, 2010 5:26 AM
  • "About how to dock with start page, please refer to the code in my previous reply. And see the following picture whether it’s the result you want"

    No, that's not what I want. I want the new tool window to doc with / at the same level as the start page.

     

    No, CreateToolWindows2 does not fail. My tool window does get created. But, trying to link it using CreateLinkedWindowFrame crashes. Once again, if you know that this works, and know how to make it work, just give me the code.

    Tuesday, March 30, 2010 8:11 PM
  • Try the following code.

    ToolWindowPane window = this.FindToolWindow(typeof(MyToolWindow), 0, true);
    
    if (null == window
    
       || null == window.Frame)
    
    {
    
    	throw new NotSupportedException(Resources.CanNotCreateWindow);
    
    }
    
    IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame as IVsWindowFrame;
    
    windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, VSFRAMEMODE.VSFM_MdiChild);
    
    Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
    
    

    Note: I wrote the above code in a sample package, not in add in. Hence use something else instead "this.FindToolWindow(....)"


    Kiran Chand Palakkattiri
    [Life is not a personality contest]
    kiran.chand@live.in


    Thanks Kiran, but i'm not making a VS Package, i'm doing an addin, so your code doesn't help me much.

     

    Tuesday, March 30, 2010 10:27 PM
  • Hi Ike,

    Thanks for your feedback.

    Based on my research, if you want your tool window as tabbed document like Start Page, you don't need to use CreateLinkedWindowFrame() function.To make a toolwindow to appear as a tabbed window, you have to set both two properties of the EnvDTE.Window class: IsFloating and Linkable to false. Please refer to following code:

    if (this.win == null)
        this.CreateToolWindow();
    
    _applicationObject.MainWindow.LinkedWindows.Add(this.win);
    this.win.Linkable = false;
    this.win.IsFloating = false;

    For details information, please see Carlos's article: HOWTO: Understanding toolwindow states in Visual Studio .

    About sample, you can download my test sample (MyAddin6) from the link:

    http://cid-31c5ffcfa328f712.skydrive.live.com/browse.aspx/Sample/Tool%20Window%20as%20Tabbed%20Document?uc=2

    Don't forget to copy MyAddin6-For testing to the folder C:\Users\usernmae\Documents\Visual Studio 2008\Addins\.

    Please let me know if you have any comments.

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 1, 2010 6:20 AM
  • Making progress!

    Now, it works when my add-in attempts to create the Tool Window as a result of the menu item being clicked.

    But, if I attempt to create the Tool Window from the OnConnection event handler, then I get the same access violation exception on the call to LinkedWindows.Add:
    _applicationObject.MainWindow.LinkedWindows.Add(newToolWindow);

    Thursday, April 1, 2010 6:36 AM
  • It seems I don't need the call to LinkedWindows.Add.

    Setting the Linkable property to false is all it takes.

    Now it's working perfectly in VS 2005, 2008 & 2010!

    Thanks for your help!

    • Marked as answer by Ike Starnes Thursday, April 1, 2010 6:52 AM
    Thursday, April 1, 2010 6:52 AM
  • Hi Ike,

    Glad to hear it works.

    -Nancy

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 1, 2010 6:59 AM