Home > Code Samples > How to show and dock a tool window automatically on Visual Studio start-up

How to show and dock a tool window automatically on Visual Studio start-up

November 15th, 2010

If you’d like to show your tool window from a DXCore-based ToolWindow plug-in, you have to create another standard plug-in that will do this. You can add an additional DXCore standard plug-in project item into your solution, where the tool window is located. In the new plug-in, you need to handle the DXCoreLoaded event and manually add a code that opens and shows a tool window.

Follow these steps to accomplish the task:

1) In the tool window you created, add the following code:

using Microsoft.VisualStudio.Shell.Interop;
using DevExpress.DXCore.Interop;

private static IVsWindowFrame GetWindowFrameFromGuid(Guid guid)
{
  Guid slotGuid = guid;
  IVsWindowFrame wndFrame;
  VisualStudioServices.VsUIShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fFrameOnly, ref slotGuid, out wndFrame);
  return wndFrame;
}

private static IVsWindowFrame GetWindowFrameFromWindow(EnvDTE.Window window)
{
  if (window == null)
    return null;
  if (window.ObjectKind == null || window.ObjectKind == String.Empty)
    return null;
  return GetWindowFrameFromGuid(new Guid(window.ObjectKind));
}

public static void ShowWindowDocked()
{
  EnvDTE.Window window = CodeRush.ToolWindows.Show(typeof(YourToolWindowClassName));
  if (window != null)
  {
    IVsWindowFrame wndFrame = GetWindowFrameFromWindow(window);
    if (wndFrame != null)
      wndFrame.SetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, VSFRAMEMODE.VSFM_MdiChild);
  }
}

2) In the newly created StandardPlugIn instance, subscribe to the DXCoreLoaded event, using the designer surface, and add the following code that will show up in your tool window:

void EventNexus_DXCoreLoaded(DXCoreLoadedEventArgs ea)
{
  YourToolWindowClassName.ShowWindowDocked();
}

After that, when DXCore is loaded (manually or automatically on Visual Studio start-up) the standard plug-in will open up the tool window and dock it inside the code editor.

The source and the binary are attached.

—–
Products: DXCore
Versions: 10.1 and up
VS IDEs: any
Updated: Mar/25/2011
ID: D034

Similar Posts:

  1. Le
    March 24th, 2011 at 07:06 | #1

    Hi,

    I can’t seem how you can wire up to the EventNexus_DXCoreLoaded event via the design surface, I tried wiring this up manually and I can’t seem to find the event eithier in the code-behind of my standard plugin, lastly I tried searching to see where this event is raised with Reflector and no luck there eithier?

    Thanks in advance,

    -Le

  2. March 24th, 2011 at 10:27 | #2

    @ Le
    There’s the EventNexus class, where you can wire up the DXCoreLoaded event, like this:

    DevExpress.CodeRush.Core.EventNexus.DXCoreLoaded += DXCoreLoadedHandler;

  3. Le
    March 24th, 2011 at 10:59 | #3

    Sweeeeeeeeet, worked like a charm….!

  4. Le
    March 24th, 2011 at 11:16 | #4

    This docks to the bottom of VS, is there anyway to get the toolwindow to dock to the left, I’ve tried every enum from:

    public enum VSFRAMEMODE
    {
    VSFM_Dock = 0,
    VSFM_Float = 1,
    VSFM_MdiChild = 2,
    VSFM_FloatOnly = 3,
    }

    and didn’t seem like any of them did the trick.

  5. March 24th, 2011 at 12:49 | #5

    @ Le
    Once you dock the tool window on the left manually, Visual Studio will remain the dock state of the tool window automatically.
    Probably the IVsWindowFrame.SetFramePos call might do the trick too.