public void Ensure(SolutionExplorerWindow solutionExplorerWindow)
        {
            if (solutionExplorerWindow == null)
                throw new ArgumentNullException("solutionExplorerWindow");

            EnsureControl(solutionExplorerWindow);

            if (_useVisualGitIcons)
                SetIcons();
        }
        private void EnsureControl(SolutionExplorerWindow solutionExplorerWindow)
        {
            if (_treeViewControl != null && _treeViewControl.IsValid)
                return;

            EnvDTE.Window window;
            try
            {
                window = VsShellUtilities.GetWindowObject(solutionExplorerWindow.SolutionExplorerFrame);
            }
            catch (COMException)
            {
                // for VS2010 - WPF Shell compatibility (we cannot find the solutionexplorer frame there)
                return;
            }

            string expCaption = window.Caption;

            IntPtr handle = IntPtr.Zero;

            if (window.HWnd != 0)
            {
                // We've got the parent
                handle = (IntPtr)window.HWnd;
            }
            else
            {
                EnvDTE.Window hostWindow = window.LinkedWindowFrame;

                if (hostWindow != null)
                    handle = SearchForSolutionExplorer((IntPtr)hostWindow.HWnd, expCaption);

                if (handle == IntPtr.Zero)
                {
                    hostWindow = window.DTE.MainWindow;

                    if (hostWindow != null)
                        handle = SearchForSolutionExplorer((IntPtr)hostWindow.HWnd, expCaption);
                }

                if (handle == IntPtr.Zero)
                    handle = SearchFloatingPalettes(expCaption);
            }

            if (handle == IntPtr.Zero)
                return; // Not found :(

            IntPtr uiHierarchy = NativeMethods.FindWindowEx(handle, IntPtr.Zero,
                UIHIERARCHY, null);
            IntPtr treeHwnd = NativeMethods.FindWindowEx(uiHierarchy, IntPtr.Zero, TREEVIEW,
                null);

            if (treeHwnd == IntPtr.Zero)
                return;

            this._treeViewControl = new Win32TreeView(treeHwnd);
        }