如何根据文件夹的路径获取LPITEMIDLIST指针?

时间:2023-01-17 08:26:22

I want to get the system icon of a specified folder, but maybe the only way to retrieve the icon is to use SHGetFileInfo() method. The first parameter of SHGetFileInfo() method is a pointer of LPITEMIDLIST.

我想获取指定文件夹的系统图标,但是检索图标的唯一方法是使用SHGetFileInfo()方法。 SHGetFileInfo()方法的第一个参数是LPITEMIDLIST的指针。

If I only have the absolute path of the folder, how can I get the pointer according to the path?

如果我只有文件夹的绝对路径,我如何根据路径获取指针?

1 个解决方案

#1


SHParseDisplayName().

Welcome to the wonderful world of PIDLs.

欢迎来到精彩的PIDL世界。

You can read more at Introduction to the Shell Namespace, but basically a PIDL is a Pointer to an item ID List. You can think of it as a linked list in contiguous memory, but instead of each node having a pointer to the next node, you instead have the cb member which is the Count of Bytes that are contained the item, so you can add that to the base address to get the next item. IDLists are terminated with an item with { cb = 0, abID = NULL }.

您可以在Shell命名空间简介中阅读更多内容,但基本上PIDL是指向项目ID列表的指针。您可以将其视为连续内存中的链接列表,但不是每个节点都有指向下一个节点的指针,而是使用cb成员,该成员是包含该项的字节数,因此您可以将其添加到获取下一个项目的基地址。 IDLists以{cb = 0,abID = NULL}的项终止。

So, what's in these magic lits? Basically you don't care and can't know. Any IShellFolder implementation can create a new type of ID to represent its type of item in the shell namespace. The basic file system view that the Shell implements just stores the parts of the path in these lists, so you have something like "c:\" in the first one "Users\" in the next one, etc. In reality they are serialized structs (or classes) that may contain more data. But they can also represent printers, network shares, database searches (for search folders, stacks, etc).

那么,这些神奇的东西是什么?基本上你不在乎也无法知道。任何IShellFolder实现都可以创建一种新类型的ID来表示shell命名空间中的项类型。 Shell实现的基本文件系统视图只是将路径的各个部分存储在这些列表中,所以你在下一个中的第一个“Users \”中有类似“c:\”的东西,等等。实际上它们是序列化的可能包含更多数据的结构(或类)。但它们也可以代表打印机,网络共享,数据库搜索(搜索文件夹,堆栈等)。

All you really need to know is you can ask IShellFolders to give you a PIDL that represents the items they contain, and later on you can give that PIDL back to them, and other various Shell functions and interfaces, and they know how to deal with them. What SHParseDisplayName() basically does (I think) is go through the registry looking for all registered IShellFolder implementations and asks them if they know what to do with the string you pass in, and the first one to handle it makes the PIDL and gives it back.

您真正需要知道的是,您可以要求IShellFolders为您提供一个表示它们包含的项目的PIDL,稍后您可以将PIDL返回给它们,以及其他各种Shell函数和接口,并且它们知道如何处理他们。什么SHParseDisplayName()基本上(我认为)是通过注册表查找所有已注册的IShellFolder实现,并询问他们是否知道如何处理您传入的字符串,并且第一个处理它的人生成PIDL并给它背部。

#1


SHParseDisplayName().

Welcome to the wonderful world of PIDLs.

欢迎来到精彩的PIDL世界。

You can read more at Introduction to the Shell Namespace, but basically a PIDL is a Pointer to an item ID List. You can think of it as a linked list in contiguous memory, but instead of each node having a pointer to the next node, you instead have the cb member which is the Count of Bytes that are contained the item, so you can add that to the base address to get the next item. IDLists are terminated with an item with { cb = 0, abID = NULL }.

您可以在Shell命名空间简介中阅读更多内容,但基本上PIDL是指向项目ID列表的指针。您可以将其视为连续内存中的链接列表,但不是每个节点都有指向下一个节点的指针,而是使用cb成员,该成员是包含该项的字节数,因此您可以将其添加到获取下一个项目的基地址。 IDLists以{cb = 0,abID = NULL}的项终止。

So, what's in these magic lits? Basically you don't care and can't know. Any IShellFolder implementation can create a new type of ID to represent its type of item in the shell namespace. The basic file system view that the Shell implements just stores the parts of the path in these lists, so you have something like "c:\" in the first one "Users\" in the next one, etc. In reality they are serialized structs (or classes) that may contain more data. But they can also represent printers, network shares, database searches (for search folders, stacks, etc).

那么,这些神奇的东西是什么?基本上你不在乎也无法知道。任何IShellFolder实现都可以创建一种新类型的ID来表示shell命名空间中的项类型。 Shell实现的基本文件系统视图只是将路径的各个部分存储在这些列表中,所以你在下一个中的第一个“Users \”中有类似“c:\”的东西,等等。实际上它们是序列化的可能包含更多数据的结构(或类)。但它们也可以代表打印机,网络共享,数据库搜索(搜索文件夹,堆栈等)。

All you really need to know is you can ask IShellFolders to give you a PIDL that represents the items they contain, and later on you can give that PIDL back to them, and other various Shell functions and interfaces, and they know how to deal with them. What SHParseDisplayName() basically does (I think) is go through the registry looking for all registered IShellFolder implementations and asks them if they know what to do with the string you pass in, and the first one to handle it makes the PIDL and gives it back.

您真正需要知道的是,您可以要求IShellFolders为您提供一个表示它们包含的项目的PIDL,稍后您可以将PIDL返回给它们,以及其他各种Shell函数和接口,并且它们知道如何处理他们。什么SHParseDisplayName()基本上(我认为)是通过注册表查找所有已注册的IShellFolder实现,并询问他们是否知道如何处理您传入的字符串,并且第一个处理它的人生成PIDL并给它背部。