public int GetSpecialFolderIcon(WindowsSpecialFolder folder) { EnsureSpecialImages(); int index; if (_folderMap.TryGetValue(folder, out index)) { return(index); } IntPtr pidl = IntPtr.Zero; try { if (VSErr.S_OK != NativeMethods.SHGetFolderLocation(IntPtr.Zero, folder, IntPtr.Zero, 0, out pidl)) { return(-1); } NativeMethods.SHFILEINFO fileinfo = new NativeMethods.SHFILEINFO(); IntPtr sysImageList = NativeMethods.SHGetFileInfoW(pidl, (uint)(int)FileAttributes.Directory, ref fileinfo, (uint)Marshal.SizeOf(fileinfo), NativeMethods.SHGFI_SHELLICONSIZE | NativeMethods.SHGFI_SYSICONINDEX | NativeMethods.SHGFI_SMALLICON | NativeMethods.SHGFI_PIDL); if (sysImageList == IntPtr.Zero) { return(-1); } ProjectIconReference handle = new ProjectIconReference(sysImageList, fileinfo.iIcon); return(_folderMap[folder] = ResolveReference(handle)); } finally { if (pidl != IntPtr.Zero) { Marshal.FreeCoTaskMem(pidl); } } }
public int GetSpecialFolderIcon(WindowsSpecialFolder folder) { EnsureSpecialImages(); int index; if (_folderMap.TryGetValue(folder, out index)) return index; IntPtr pidl = IntPtr.Zero; try { if (VSConstants.S_OK != NativeMethods.SHGetFolderLocation(IntPtr.Zero, folder, IntPtr.Zero, 0, out pidl)) return -1; NativeMethods.SHFILEINFO fileinfo = new NativeMethods.SHFILEINFO(); IntPtr sysImageList = NativeMethods.SHGetFileInfoW(pidl, (uint)(int)FileAttributes.Directory, ref fileinfo, (uint)Marshal.SizeOf(fileinfo), NativeMethods.SHGFI_SHELLICONSIZE | NativeMethods.SHGFI_SYSICONINDEX | NativeMethods.SHGFI_SMALLICON | NativeMethods.SHGFI_PIDL); if (sysImageList == IntPtr.Zero) return -1; ProjectIconReference handle = new ProjectIconReference(sysImageList, fileinfo.iIcon); return _folderMap[folder] = ResolveReference(handle); } finally { if (pidl != IntPtr.Zero) Marshal.FreeCoTaskMem(pidl); } }
public static extern int SHGetFolderLocation(IntPtr hwndOwner, [MarshalAs(UnmanagedType.I4)] WindowsSpecialFolder nFolder, IntPtr hToken, uint dwReserved, out IntPtr ppidl);