Pablo Galiano : Tuesday, September 02, 2008 - Posts

Subscriptions

<September 2010>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

News

Subscribe to Pablo Galiano by Email

Post Categories

Tuesday, September 02, 2008 - Posts

How do I obtain an IVsHierarchy itemid

My fifteenth How do I is up.

Scenario

Several methods in the VS Interop world receive a IVsHierarchy item id parameter as an argument.

The problem is that there is no easy way to obtain the item id for a IVsHierarchy. Ideally we would like to do IVsHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ItemId, out itemId) but that property doesn't exist.

The focus of this How do I tackles this scenario.

 

Interfaces and classes needed

 

Code snippet

    public uint GetItemId(IVsHierarchy hierarchy)

    {

        object extObject;

        uint itemId = 0;

        IVsHierarchy tempHierarchy;

 

        hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_BrowseObject, out extObject);

 

        IVsBrowseObject browseObject = extObject as IVsBrowseObject;

 

        if(browseObject != null)

        {

            browseObject.GetProjectItem(out tempHierarchy, out itemId);

        }

 

        return itemId;

    }

 

Assemblies needed

  • Microsoft.VisualStudio.Shell.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

 

Stay tuned,

Pablo

posted Tuesday, September 02, 2008 6:54 AM by pga with 6491 Comments

How do I deal with the Visual Studio status bar

My sixteenth How do I is up.

Scenario

It is always a best practice to inform the user what is going on when we need to perform a long running operation. For that purpose Visual Studio has the status bar:

st.png

There are several options when dealing with the Visual Studio status bar, we can write messages, display progress and animations, etc. The focus of this How do I tackles these scenarios.

 

Interfaces and classes needed

 

Code snippet

    int frozen;

    IVsStatusbar statusBar = serviceProvider.GetService(typeof(SVsStatusbar)) asIVsStatusbar;

 

    statusBar.IsFrozen(out frozen);

 

    //Write to the status bar

    if(!Convert.ToBoolean(frozen))

    {

        statusBar.SetText("The Message");

 

        //Do process

        Thread.Sleep(5000);

 

        statusBar.Clear();

    }

 

    //Write and display animatio in the status bar

    if(!Convert.ToBoolean(frozen))

    {

        //The built icons that can be used are defined in Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_*

 

        object icon = (short)Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_General;

 

        statusBar.Animation(1, ref icon);

        statusBar.SetText("The Message");

 

        //Do process

        Thread.Sleep(5000);

 

        statusBar.Animation(0, ref icon);

        statusBar.Clear();

    }

 

    //Display progress in the status bar

    if(!Convert.ToBoolean(frozen))

    {

        uint userId = (uint)Microsoft.VisualStudio.Shell.Interop.Constants.VSCOOKIE_NIL;

 

        for(int i = 1; i <= 10; i++)

        {

            statusBar.Progress(ref userId, 1, "The Message", (uint)i * 10, (uint)100);

 

            //Do process

            Thread.Sleep(1000);

        }

 

        statusBar.Progress(ref userId, 0, string.Empty, 0, 0);

    }

 

Assemblies needed

  • Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

 

Stay tuned,

Pablo

posted Tuesday, September 02, 2008 7:51 AM by pga with 2 Comments