IDesignerHost using VSIP

We have a task where we create a custom toolbox and then drag and drop components

to the open documents(winforms) in the VS.Net 2005 IDE. We have a VSIP package for this.

I was trying to get the DesignerHost for the current open window so that we can add components to

the container. I could do this using the SDTE service and then getting the DesignerHost from it shown below.

DTE sdte = this.GetService(typeof(SDTE)) as DTE;

if (sdte != null)

{

if (sdte.ActiveDocument != null)

foreach (Window W in sdte.ActiveDocument.Windows)

{

IDesignerHost Host = W.Object as IDesignerHost;

if (Host != null)

return Host;

}

}

return null;

The DesignerHost has a container where we can add components.

But there was a mention of not using the Automation model (DTE) with the VSIP package (MPF).

I then tried getting the active window using the IVsUIShell service and then getting the

Windowframe from it. However the DesignerHost is not exposed. Is there a way

where we can get it.

IVsUIShell uiShell = GetService(typeof(SVsUIShell)) as IVsUIShell;

IEnumWindowFrames windowFramesEnum;

uiShell.GetDocumentWindowEnum(out windowFramesEnum);

windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out data)

The purpose here is to add components to the document in the Vs.Net ide. Any other

approach would also be helpful.



Answer this question

IDesignerHost using VSIP

  • Grigory Bushuev

    Hi. In your post you say:

    "But there was a mention of not using the Automation model (DTE) with the VSIP package (MPF)"

    Can you tell me where you learned of this.

    Thanks,

    Herman Post


  • MavecO

    You can access the IDesignerHost interface using the following code snippet.

    // Get the window frame object for document associated with the IDesignerHost

    string logicalViewGuid = EnvDTE.Constants.vsViewKindDesigner;

    IVsWindowFrame windowFrame;

    System.IServiceProvider serviceProvider = this.ProjectMgr.Site; // Use your global service provider object

    string fullPathToDocument = this.Url; // Use whatever full path you have to the document

    IVsUIHierarchy hier;

    uint itemid;

    Microsoft.VisualStudio.Shell.VsShellUtilities.IsDocumentOpen(serviceProvider, fullPathToDocument, new Guid(logicalViewGuid), out hier, out itemid, out windowFrame);

    if (windowFrame != null)

    {

    object docView;

    windowFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView);

    if (docView != null)

    {

    System.IServiceProvider sp = docView as System.IServiceProvider;

    if (sp != null)

    {

    System.ComponentModel.Design.IDesignerHost host = sp.GetService(typeof(System.ComponentModel.Design.IDesignerHost)) as System.ComponentModel.Design.IDesignerHost;

    System.Diagnostics.Debug.WriteLine(host.RootComponentClassName);

    }

    }

    }

    /Ole


  • Samster

    Hi Ole,thanks for the reply. it works. ~ Atul
  • IDesignerHost using VSIP