Exemplo n.º 1
0
        static int ChangeFolder(ShellDebuggerModel model, IntPtr pidl,
                                SBSP wFlags, IShellFolder folderTmp, IntPtr pidlTmp)
        {
            model.currentFolder = folderTmp;
            var Form = model.Form;

            FOLDERSETTINGS fs              = new FOLDERSETTINGS();
            IShellView     lastIShellView  = model.ShellView;
            IShellView2    lastIShellView2 = model.ShellView as IShellView2;

            if (lastIShellView != null)
            {
                lastIShellView.GetCurrentInfo(ref fs);
            }
            // Copy the old folder settings
            else
            {
                fs          = new FOLDERSETTINGS();
                fs.fFlags   = ShellDebuggerModel.folderFlags;
                fs.ViewMode = ShellDebuggerModel.folderViewMode;
            }

            // Create the IShellView
            IntPtr iShellViewPtr;
            var    shellViewGuid = typeof(IShellView).GUID;
            var    hr            = ShellObject.CreateViewObject(folderTmp, Form.Handle,
                                                                ref shellViewGuid, out iShellViewPtr);

            if (hr != WinError.S_OK)
            {
                shellViewGuid = typeof(IShellView).GUID;
                hr            = ShellObject.CreateViewObject(folderTmp, Form.Handle,
                                                             ref shellViewGuid, out iShellViewPtr);
            }

            if (hr == WinError.S_OK)
            {
                model.ShellView = null;
                model.ShellView = (IShellView) // IShellView2
                                  Marshal.GetObjectForIUnknown(iShellViewPtr);
                //if (model.ShellView == null)
                //    model.ShellView = (IShellView)
                //               Marshal.GetObjectForIUnknown(iShellViewPtr);
                // int CreateViewWindow2(SV2CVW2_PARAMS lpParams);

                var  hWndListView = IntPtr.Zero;
                RECT rc           =
                    new RECT(0, 0,
                             Form.ClientSize.Width,
                             Form.ClientSize.Height);

                int res;
                model.lastViewPidl = IntPtr.Zero;
                var shellView = model.ShellView;

                try
                {
                    // Create the actual list view.
                    res = shellView.CreateViewWindow(lastIShellView, ref fs,
                                                     model, ref rc, ref hWndListView);

                    model.hWndListView = hWndListView;
                    shellView.EnableModeless(true);
                }
                catch (COMException)
                {
                    return(WinError.E_FAIL);
                }

                if (res < 0)
                {
                    return(WinError.E_FAIL);
                }

                // Release the old IShellView
                if (lastIShellView != null)
                {
                    lastIShellView.GetCurrentInfo(ref fs);
                    lastIShellView.UIActivate(SVUIA_STATUS.SVUIA_DEACTIVATE);
                    lastIShellView.DestroyViewWindow();
                }

                // Set focus to the IShellView
                model.ShellView.UIActivate(SVUIA_STATUS.SVUIA_ACTIVATE_FOCUS);
                model.currentAbsolutePidl = pidlTmp;

                if (model.lastViewPidl != IntPtr.Zero)
                {
                    //    var lastItem = model.LastSelected;
                }
                //else
                //{
                //    // empty list
                //}
            }

            return(WinError.S_OK);
        }
Exemplo n.º 2
0
 public ShellDebuggerForm()
 {
     InitializeComponent();
     Model = new ShellDebuggerModel(this);
 }
Exemplo n.º 3
0
        public static int BrowseObject(this ShellDebuggerModel model, IntPtr pidl, SBSP wFlags)
        {
            int          hr;
            IntPtr       folderTmpPtr;
            IShellFolder folderTmp = null;
            IntPtr       pidlTmp;

            //  We'll need the shell folder GUID.
            var shellFolderGuid     = typeof(IShellFolder).GUID;
            var desktopFolder       = model.DesktopFolder;
            var currentFolder       = model.currentFolder;
            var currentAbsolutePidl = model.currentAbsolutePidl;

            //  Check to see if we have a desktop pidl, relative pidl or absolite pidl.
            if (Shell32.ILIsEqual(pidl, model.DesktopFolderPidl))
            {
                //  The provided PIDL is the desktop folder.
                pidlTmp   = Shell32.ILClone(model.DesktopFolderPidl);
                folderTmp = model.DesktopFolder;
            }
            else if ((wFlags & SBSP.SBSP_RELATIVE) != 0)
            {
                // SBSP_RELATIVE - pidl is relative from the current folder
                if ((hr = currentFolder.BindToObject(pidl, IntPtr.Zero,
                                                     shellFolderGuid,
                                                     out folderTmpPtr)) != WinError.S_OK)
                {
                    return(WinError.E_FAIL);
                }

                pidlTmp = Shell32.ILCombine(currentAbsolutePidl, pidl);

                folderTmp = (IShellFolder)Marshal.GetObjectForIUnknown(folderTmpPtr);
            }
            else
            {
                // SBSP_ABSOLUTE - pidl is an absolute pidl (relative from desktop)
                pidlTmp = Shell32.ILClone(pidl);
                if ((hr = desktopFolder.BindToObject(pidlTmp, IntPtr.Zero,
                                                     shellFolderGuid,
                                                     out folderTmpPtr)) != WinError.S_OK)
                {
                    return(WinError.E_FAIL);
                }

                folderTmp = (IShellFolder)Marshal.GetObjectForIUnknown(folderTmpPtr);
            }

            if (folderTmp == null)
            {
                Shell32.ILFree(pidlTmp);
                return(WinError.E_FAIL);
            }

            // Check that we have a new pidl
            if (Shell32.ILIsEqual(pidlTmp, currentAbsolutePidl))
            {
                Shell32.ILFree(pidlTmp);
                return(WinError.S_OK);
            }

            model.hWndListView = IntPtr.Zero;
            model.lastViewPidl = IntPtr.Zero;

            var ret = ChangeFolder(model, pidl, wFlags, folderTmp, pidlTmp);

            //var path = PidlManager.GetPidlDisplayName(pidlTmp);
            //if (path == "Control Panel" || model.lastViewPidl == IntPtr.Zero)
            //{
            //    IEnumIDList ppenumIDList = null;
            //    var hr3 = folderTmp.EnumObjects(model.Form.Handle,
            //        SHCONTF.SHCONTF_INCLUDEHIDDEN | SHCONTF.SHCONTF_INCLUDESUPERHIDDEN | SHCONTF.SHCONTF_NONFOLDERS, // | SHCONTF.SHCONTF_FOLDERS ,
            //        out ppenumIDList);

            //    if (ppenumIDList == null)       // if empty list
            //    {
            //        IntPtr iShellFolderPtr = IntPtr.Zero;
            //        var guidFolder2 = typeof(IShellFolder2).GUID;
            //        folderTmpPtr = IntPtr.Zero;

            //        if ((hr = desktopFolder.BindToObject(pidlTmp, IntPtr.Zero,
            //            ref guidFolder2, // shellFolderGuid,
            //            out folderTmpPtr)) == WinError.S_OK)
            //        {
            //            folderTmp = (IShellFolder2)Marshal.GetObjectForIUnknown(folderTmpPtr);

            //            var hr2 = ShellObject.CreateViewObject(folderTmp, model.Form.Handle, ref guidFolder2, out iShellFolderPtr);
            //        }

            //        if (iShellFolderPtr != IntPtr.Zero)
            //        {
            //            var ShellFolder = (IShellFolder2)
            //                           Marshal.GetObjectForIUnknown(iShellFolderPtr);
            //        }
            //    }
            //}

            return(ret == WinError.S_OK ? WinError.S_OK : WinError.E_FAIL);
        }