/// <summary> /// Constructor for the desktop shell item. /// </summary> /// <param name="explorer"> /// Explorer class that uses the shell item. /// </param> /// <param name="pidl"> /// Pointer to the desktop PIDL. /// </param> /// <param name="folderPtr"> /// Pointer to the IShellFolder interface for the desktop. /// </param> internal ShellItem(ShellExplorer explorer, IntPtr pidl, IntPtr folderPtr) { this.explorer = explorer; parent = null; this.folderPtr = folderPtr; // get managed object this.folder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(folderPtr, typeof(IShellFolder)); subFiles = new ShellItemList(this); subFolders = new ShellItemList(this); relPidl = new PIDL(pidl, false); text = "Desktop"; path = "Desktop"; SetDesktopAttributes(); ShellAPI.SHFILEINFO info = new ShellAPI.SHFILEINFO(); ShellAPI.SHGetFileInfo(relPidl.Ptr, 0, ref info, ShellAPI.cbFileInfo, ShellAPI.SHGFI.PIDL | ShellAPI.SHGFI.TYPENAME | ShellAPI.SHGFI.SYSICONINDEX); type = info.szTypeName; ShellImageList.SetIconIndex(this, info.iIcon, false); ShellImageList.SetIconIndex(this, info.iIcon, true); }
/// <summary> /// Constructor for a folder item. /// </summary> /// <param name="explorer"> /// Explorer class that uses the shell item. /// </param> /// <param name="parent"> /// Parent shell item for this item. /// </param> /// <param name="pidl"> /// Pointer to the folder PIDL. /// </param> /// <param name="folderPtr"> /// Pointer to the IShellFolder interface for the folder. /// </param> internal ShellItem(ShellExplorer explorer, ShellItem parent, IntPtr pidl, IntPtr folderPtr) { this.explorer = explorer; this.parent = parent; this.folderPtr = folderPtr; folder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(folderPtr, typeof(IShellFolder)); subFiles = new ShellItemList(this); subFolders = new ShellItemList(this); relPidl = new PIDL(pidl, false); SetText(); SetPath(); SetInfo(); SetFolderAttributes(); }
/// <summary> /// Constructor for a file item. /// </summary> /// <param name="explorer"> /// Explorer class that uses the shell item. /// </param> /// <param name="parent"> /// Parent shell item for this item. /// </param> /// <param name="pidl"> /// Pointer to the file PIDL. /// </param> internal ShellItem(ShellExplorer explorer, ShellItem parent, IntPtr pidl) { this.explorer = explorer; this.parent = parent; folderPtr = IntPtr.Zero; folder = null; subFiles = null; subFolders = null; relPidl = new PIDL(pidl, false); SetText(); SetPath(); SetInfo(); SetFileAttributes(); }
/// <summary> /// Retrieve the string that describes the file's type. /// </summary> private void SetInfo() { PIDL fullPidl = FullPidl; ShellAPI.SHFILEINFO info = new ShellAPI.SHFILEINFO(); ShellAPI.SHGetFileInfo(fullPidl.Ptr, 0, ref info, ShellAPI.cbFileInfo, ShellAPI.SHGFI.PIDL | ShellAPI.SHGFI.TYPENAME | ShellAPI.SHGFI.SYSICONINDEX); fullPidl.Free(); type = info.szTypeName; ShellImageList.SetIconIndex(this, info.iIcon, false); ShellImageList.SetIconIndex(this, info.iIcon, true); }