/// <summary> /// Retrieves the display name for the specified file object or subfolder. /// Return value: error code, if any /// </summary> /// <param name="pidl">Address of an ITEMIDLIST structure (PIDL) that uniquely identifies the file object or subfolder relative to the parent folder.</param> /// <param name="uFlags">Flags used to request the type of display name to return. For a list of possible values.</param> /// <param name="pName">Address of a STRRET structure in which to return the display name.</param> /// <returns> /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// </returns> int IShellFolder.GetDisplayNameOf(IntPtr pidl, SHGDNF uFlags, out STRRET pName) { // If we have an invalid PIDL, we must fail. if (pidl == IntPtr.Zero) { pName = new STRRET(); return(WinError.E_INVALIDARG); } // Create an idlist from the pidl. var idlist = PidlManager.PidlToIdlist(pidl); // Get the shell item. // TODO; handle errors var shellItem = GetChildItem(idlist); // If the flags are normal only, we're asking for the display name only. if (uFlags == SHGDNF.SHGDN_NORMAL) { // We only need the display name. pName = STRRET.CreateUnicode(shellItem.GetDisplayName(DisplayNameContext.OutOfFolder)); return(WinError.S_OK); } // If the flags are in folder, we're asking for the standard display name. if (uFlags == SHGDNF.SHGDN_INFOLDER || uFlags == SHGDNF.SHGDN_FORADDRESSBAR) { pName = STRRET.CreateUnicode(shellItem.GetDisplayName(DisplayNameContext.Normal)); return(WinError.S_OK); } // If the flags indicate parsing mode, we need to construct a name // that'll let us bounce from PIDL <-> name. We do this, rather than // the implementor. if (uFlags.HasFlag(SHGDNF.SHGDN_FORPARSING)) { // It's either relative (INFOLDER) or fully qualified. var str = uFlags.HasFlag(SHGDNF.SHGDN_INFOLDER) ? idlist.ToParsingString() : /* TODO start with my id list */ idlist.ToParsingString(); pName = STRRET.CreateUnicode(str); return(WinError.S_OK); } pName = STRRET.CreateUnicode(string.Empty); return(WinError.S_OK); }
int IShellFolder2.GetDetailsOf(IntPtr pidl, uint iColumn, out SHELLDETAILS psd) { // Get the folder view columns. var columns = ((DefaultNamespaceFolderView)lazyFolderView.Value).Columns; // If details are being requested for a column we don't have, we must fail. if (iColumn >= columns.Count) { psd = new SHELLDETAILS { cxChar = 0, fmt = 0, str = new STRRET { uType = STRRET.STRRETTYPE.STRRET_WSTR, data = IntPtr.Zero } }; return(WinError.E_FAIL); } // If we have no pidl, we need the details of the column itself. if (pidl == IntPtr.Zero) { var column = columns[(int)iColumn]; // Create the column format. int format = 0; switch (column.ColumnAlignment) { case ColumnAlignment.Left: format = (int)LVCFMT.LVCFMT_LEFT; break; case ColumnAlignment.Centre: format = (int)LVCFMT.LVCFMT_CENTER; break; case ColumnAlignment.Right: format = (int)LVCFMT.LVCFMT_RIGHT; break; default: throw new ArgumentOutOfRangeException(); } // Set the column icon flag (if we have one). if (column.HasImage) { format |= (int)LVCFMT.LVCFMT_COL_HAS_IMAGES; } // TODO I have no idea why the shell details are not correctly respecting the cxChar.. // Create shell details for the column. psd = new SHELLDETAILS { fmt = format, cxChar = column.Name.Length, str = STRRET.CreateUnicode(column.Name) }; } else { // We've been asked for the details of an item. // Get the column ID. PROPERTYKEY propertyKey; ((IShellFolder2)this).MapColumnToSCID(iColumn, out propertyKey); // Get the value of an item at a column. var valueText = GetItemColumnValue(pidl, propertyKey); psd = new SHELLDETAILS { fmt = 0, // todo, currently set to 'left'. cxChar = valueText.Length, str = STRRET.CreateUnicode(valueText) }; } return(WinError.S_OK); }