[英]How do I determine the icon index for Desktop and Network for use in SHGetImageList?
I am able to successfully extract the icons for file system drives, folders and files using the APIs I included below. 我可以使用下面包含的API成功提取文件系统驱动器,文件夹和文件的图标。 Additional info on the DLL imports etc. that helped me get this far can be found here .
可以在这里找到有关DLL导入等的其他信息,这些信息可以帮助我进一步发展。 By calling the method
GetExtraLargeIconForFolder
I get a 48x48 sized image in the icon. 通过调用方法
GetExtraLargeIconForFolder
我在图标中获得了48x48尺寸的图像。
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;
}
In Windows Explorer one sees, icons for the Desktop, Network and Computer. 在Windows资源管理器中,可以看到桌面,网络和计算机的图标。 How does one go about getting the correct icon index for these file system nodes?
如何为这些文件系统节点获取正确的图标索引?
You are nearly there. 你快到了。 You still use
SHGetFileInfo
but instead you will need to pass SHGFI_PIDL
in the flags parameter. 您仍然使用
SHGetFileInfo
但您需要在flags参数中传递SHGFI_PIDL
。
Then you need to specify the shell object of interest by passing a PIDL
rather than a path. 然后,您需要通过传递
PIDL
而不是路径来指定目标外壳对象。 Obtain the PIDL
by calling SHGetSpecialFolderLocation
. 通过调用
SHGetSpecialFolderLocation
获得PIDL
。 Pass a CSIDL
value to this routine, eg CSIDL_DESKTOP
, CSIDL_DRIVES
, CSIDL_NETWORK
etc. 将
CSIDL
值传递给此例程,例如CSIDL_DESKTOP
, CSIDL_DRIVES
, CSIDL_NETWORK
等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.