1
我能够使用下面包含的API成功提取文件系统驱动器,文件夹和文件的图标。有关DLL导入等其他信息,帮助我得到这一点,可以发现here。通过调用方法GetExtraLargeIconForFolder
,我在图标中获得了48x48大小的图像。如何确定用于SHGetImageList的桌面和网络的图标索引?
public enum ImageListIconSize : int
{
Large = 0x0,
Small = 0x1,
ExtraLarge = 0x2,
Jumbo = 0x4
}
private static IImageList GetSystemImageListHandle(ImageListIconSize size)
{
IImageList iImageList;
Guid imageListGuid = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950");
int ret = SHGetImageList(
(int)size,
ref imageListGuid,
out iImageList
);
return iImageList;
}
public static Icon GetExtraLargeIconForFolder(string path)
{
SHFILEINFO shinfo = new SHFILEINFO();
IntPtr retVal = SHGetFileInfo(
path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo),
(int)(SHGetFileInfoConstants.SHGFI_SYSICONINDEX |
SHGetFileInfoConstants.SHGFI_ICON));
int iconIndex = shinfo.iIcon;
IImageList iImageList =
(IImageList)GetSystemImageListHandle(ImageListIconSize.ExtraLarge);
IntPtr hIcon = IntPtr.Zero;
if (iImageList != null)
{
iImageList.GetIcon(iconIndex,
(int)ImageListDrawItemConstants.ILD_TRANSPARENT, ref hIcon);
}
Icon icon = null;
if (hIcon != IntPtr.Zero)
{
icon = Icon.FromHandle(hIcon).Clone() as Icon;
DestroyIcon(shinfo.hIcon);
}
return icon;
}
在Windows资源管理器中,可以看到桌面,网络和计算机的图标。如何获得这些文件系统节点的正确图标索引?
如何通过CSIDL?我把它作为一个字符串或像Shell32.CSIDL?它甚至没有初始化 – 2012-01-29 23:50:32
@MurHafSoz我不能在评论中回答。这听起来像你试图挑战SHGetSpecialFolderLocation并陷入困境。如果无法解决问题,请提出问题。 – 2012-01-30 11:14:22