简体   繁体   English

如何确定要在SHGetImageList中使用的桌面和网络的图标索引?

[英]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_DESKTOPCSIDL_DRIVESCSIDL_NETWORK等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定设备是否为桌面浏览器? - How do I determine if a device is a desktop browser? 如何确定.NET中的“网络位置”? - How do I determine “Network Location” in .NET? 如何确定我的计算机正在使用哪个网络适配器? - How do I determine which network adapter my computer is using? 如何创建foreach语句以确定所选索引值是否为“ 0” - How do I create a foreach statment to determine if the selected index value is “0” 如何从C#桌面应用程序中检索Windows应用商店应用程序的图标? - How do I retrieve a Windows Store app's icon from a C# desktop app? C#如何检查a进程图标并确定它使用的是哪个 - C# How do I check the a processes icon and determine which one it is using 如何使用C#确定本地网络上的哪些IP地址是静态/动态的? - How can I use C# to determine which IP addresses on my local network are static/dynamic? 如何将包图标用作鼠标 cursor? - How do I use a Pack Icon as a mouse cursor? 如何确定我的外部网站用户是否确实在我们的办公网络内? - How do I determine if my external website user is actually inside our office network? 如何确定Windows应用程序的网络传输速度? - How do you determine the network transfer speed of a Windows application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM