SixPairs

August 28, 2013

Hide a ToolWindow at VSShell Startup

Filed under: VSShell — Tags: — Ceyhun Ciper @ 21:29
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Shell;
using EnvDTE80;

namespace Company.VSPackage1
{
    [PackageRegistration(UseManagedResourcesOnly = true)]
    [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
    [Guid(GuidList.guidVSPackage1PkgString)]
    [ProvideAutoLoad(UIContextGuids80.NoSolution)]
    public sealed class VSPackage1Package : Package, IVsShellPropertyEvents
    {
        private uint m_EventSinkCookie;

        protected override void Initialize()
        {
            base.Initialize();
        
            // Set an event listener for shell property changes
            var shellService = GetService(typeof(SVsShell)) as IVsShell;
            ErrorHandler.ThrowOnFailure(shellService.AdviseShellPropertyChanges(this, out m_EventSinkCookie));
        }

        public int OnShellPropertyChange(int propid, object val)
        {
            // We handle the event if zombie state changes from true to false
            if (propid == (int)__VSSPROPID.VSSPROPID_Zombie)
            {
                if ((bool)val == false)
                {
                    DTE2 dte = GetService(typeof(SDTE)) as DTE2;
                    dte.ExecuteCommand("View.SolutionExplorer");
                    dte.ExecuteCommand("Window.Hide");

                    // Unsubscribe from events
                    var shellService = GetService(typeof(SVsShell)) as IVsShell;
                    ErrorHandler.ThrowOnFailure(shellService.UnadviseShellPropertyChanges(m_EventSinkCookie));
                    m_EventSinkCookie = 0;

                }
            } 
            
            return VSConstants.S_OK;
        }
    }
}

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.