Copying file details from Explorer as tabular text

你离开我真会死。 提交于 2019-12-05 19:52:13

1) Create context menu shell extension. It must implement IShellExtInit, IContextMenu(2,3) and IObjectWithSite. Register your shell extension on HKCR\AllFilesystemObjects key.

2) Before Explorer calls IContextMenu.InvokeCommand it calls IObjectWithSite.SetSite. Save Site value.

3) Inside IContextMenu.InvokeCommand:

Site.QueryInterface(IServiceProvider, ServiceProvider)
ServiceProvider.QueryService(SID_SFolderView, IColumnManager, ColumnManager)
ColumnManager.GetColumnCount(CM_ENUM_VISIBLE, Count)
GetMem(Keys, SizeOf(PPropertyKey) * Count)
ColumnManager.GetColumns(CM_ENUM_VISIBLE, Keys, Count)

Now you have array of all visible columns.

4) Extract IShellFolder of current folder from IDataObject passed to your handler in IShellExtInit.Initialize.

5) Extract PItemIDList of every file in IDataObject.

6) For every PItemIDList:

6.1) Call ShellFolder.BindToObject(Child, nil, IPropertyStore, PropertyStore) to get PropertyStore of item.

6.2) For every PropertyKey in Keys array:

6.2.1) Call PropertyStore.GetValue(PropertyKey, Value);

6.2.2) Convert Value to string with PropVariantToStringAlloc function.

6.2.3) Store string representation of Value in you internal txt storage.

7) Copy your txt storage to clipboard.

8) Free all resources.

Update 1

Also you can try to use IShellFolder2.GetDetailsEx instead of using IPropertyStore.

Update 2

In case of using IPropertyStore you can additionally call IPropertySystem.FormatForDisplayAlloc to format the value. For example for PKEY_Size PropertyStore.GetValue return "100000" but PropertySystem.FormatForDisplayAlloc will format value to "100 KB".

Update 3

It was quite interesting task so I created my own shell extension which copies details to clipboard. It can be downloaded via link http://www.shellace.com/bin/CopyDetails.zip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!