我有一种情况,我想在一些Windows shell特殊文件夹(对应于CSIDL枚举中的值)上执行特殊处理.(我的解决方案必须与WinXP兼容.)我遇到的问题是当我遇到IShellFolders时我沿着heirarchy工作,我找不到将IShellFolders与CSIDL相匹配的方法.
这是我目前的做法:
将csidlToFromFullPIdl所有CSIDL 的静态一对一数据结构()初始化为其返回的pIDL SHGetSpecialFolderLocation.
foreach (CSIDL csidl in Enum.GetValues(typeof(CSIDL))
{
IntPtr fullPIdl = IntPtr.Zero;
int hResult = ShellApi.SHGetSpecialFolderLocation(IntPtr.Zero, csidl, ref fullPIdl);
if (hResult != 0)
Marshal.ThrowExceptionForHR(hResult);
csidlToFromFullPIdl.Add(csidl, fullPIdl);
}
Run Code Online (Sandbox Code Playgroud)
使用Desktop IShellFolder启动heirarchy:
int hResult = ShellApi.SHGetDesktopFolder(ref _shellFolder);
hResult = ShellApi.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, ref _fullPIdl);
Run Code Online (Sandbox Code Playgroud)
像这样检索孩子:
hResult = _shellFolder.EnumObjects(IntPtr.Zero, SHCONTF.SHCONTF_FOLDERS, out pEnum);
// Then repeatedly call:
pEnum.Next(1, out childRelativePIdl, out numberGotten);
Run Code Online (Sandbox Code Playgroud)
为孩子们构建新的完全合格的pIDL,如下所示:
_fullPIdl = ShellApi.ILCombine(parentFullPIdl, childRelativePIdl);
Run Code Online (Sandbox Code Playgroud)
(最后,使用:)检索孩子的IShellFolder
hResultUint = parentShellItem.ShellFolder.BindToObject(childRelativePIdl, IntPtr.Zero, ShellApi.IID_IShellFolder, out _shellFolder);
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是childRelativePIdl和_fullPIdl都不对应于任何pIDL csidlToFromFullPIdl.
TIA. …