【问题标题】:C#: Get file large thumbnails/previews, instead of large icons, using SHGetImageList and SHGetFileInfo, like Windows ExplorerC#:使用 SHGetImageList 和 SHGetFileInfo 获取文件大缩略图/预览,而不是大图标,如 Windows 资源管理器
【发布时间】:2011-07-08 13:28:39
【问题描述】:

我正在使用 C#、Windows 窗体、Net 2.0。

我正在使用 SHGetImageList 来获取系统映像列表,比如 SHIL_JUMBO 参数,并在 Windows 7 上获取 256x256 大图像。

[DllImport(SHELL32, EntryPoint = "#727")]
public static extern int SHGetImageList(int imageList, ref Guid riid, ref IntPtr handle);

public static IntPtr Get(SystemImageListType type)
{
    IntPtr handle = IntPtr.Zero;
    NativeMethods.SHGetImageList((int)type, ref NativeMethods.IIDImageList, ref handle);
    return handle;
}

我也在用

NativeMethods.SendMessage(listView.Handle, LVM_SETIMAGELIST, LVSIL_NORMAL, imageListHandle);

将系统图像列表设置为我的列表视图,并且

public static int GetFileIconIndex(string pathName)
{
    NativeMethods.SHFILEINFO shfiData = new NativeMethods.SHFILEINFO();

    NativeMethods.SHGetFileInfo(
        pathName,
        0,
        ref shfiData,
        Marshal.SizeOf(typeof(NativeMethods.SHFILEINFO)),
        NativeMethods.SHGFI.SYSICONINDEX |
        NativeMethods.SHGFI.LARGEICON |
        NativeMethods.SHGFI.ICON );
    return shfiData.iIcon;
}

获取列表视图中加载的不同文件/文件夹的图标索引。

一切正常,除了我得到了 256 个大图标,即使是电影或图像文件,我希望在其中有缩略图(图像/电影的预览),就像在 Windows 资源管理器中一样。

如何获取缩略图,而不是在 Windows 资源管理器中显示为缩略图的文件图标?

【问题讨论】:

    标签: c# winforms shell listview native


    【解决方案1】:

    在 Windows Vista 及以上版本中,您可以使用IThumbnailProvider 接口。

    Windows API Code Pack 中有一个包装器。

    对于 XP 有不同的界面,请参见:http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Thumbnail_Extraction/Thumbail_Tester_Code_zip_ThumbnailTester/ThumbnailCreator_cs.asp

    显然,您必须决定哪些文件将使用系统图像列表图标,哪些将使用缩略图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 2010-10-20
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多