int IShellView.GetCurrentInfo(ref FOLDERSETTINGS pfs) { pfs = new FOLDERSETTINGS {fFlags = 0, ViewMode = FOLDERVIEWMODE.FVM_AUTO}; return WinError.S_OK; }
int IShellBrowser.BrowseObject(IntPtr pidl, SBSP wFlags) { if (this.InvokeRequired) { AutoResetEvent theEvent = new AutoResetEvent(false); int result = WinError.E_FAIL; this.Invoke((Action)(() => { result = ((IShellBrowser)this).BrowseObject(pidl, wFlags); theEvent.Set(); })); theEvent.WaitOne(); return result; } int hr; IntPtr folderTmpPtr; IShellFolder folderTmp; IntPtr pidlTmp; // We'll need the shell folder GUID. var shellFolderGuid = typeof (IShellFolder).GUID; var shellViewGuid = typeof (IShellView).GUID; // Check to see if we have a desktop pidl, relative pidl or absolite pidl. if (Shell32.ILIsEqual(pidl, desktopFolderPidl)) { // The provided PIDL is the desktop folder. pidlTmp = Shell32.ILClone(desktopFolderPidl); folderTmp = desktopFolder; } else if ((wFlags & SBSP.SBSP_RELATIVE) != 0) { // SBSP_RELATIVE - pidl is relative from the current folder if ((hr = currentFolder.BindToObject(pidl, IntPtr.Zero, ref shellFolderGuid, out folderTmpPtr)) != WinError.S_OK) return hr; 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, ref shellFolderGuid, out folderTmpPtr)) != WinError.S_OK) return hr; 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; } currentFolder = folderTmp; FOLDERSETTINGS fs = new FOLDERSETTINGS(); IShellView lastIShellView = shellView; if (lastIShellView != null) lastIShellView.GetCurrentInfo(ref fs); // Copy the old folder settings else { fs = new FOLDERSETTINGS(); fs.fFlags = folderFlags; fs.ViewMode = folderViewMode; } // Create the IShellView IntPtr iShellViewPtr; hr = folderTmp.CreateViewObject(Handle, ref shellViewGuid, out iShellViewPtr); if (hr == WinError.S_OK) { shellView = (IShellView) Marshal.GetObjectForIUnknown(iShellViewPtr); hWndListView = IntPtr.Zero; RECT rc = new RECT(0, 0, ClientSize.Width, ClientSize.Height); int res; try { // Create the actual list view. res = shellView.CreateViewWindow( lastIShellView, ref fs, this, ref rc, ref hWndListView); } 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 shellView.UIActivate(SVUIA_STATUS.SVUIA_ACTIVATE_FOCUS); currentAbsolutePidl = pidlTmp; } return WinError.S_OK; }