开发者

C#: Get file large thumbnails/previews, instead of large icons, using SHGetImageList and SHGetFileInfo, like Windows Explorer

开发者 https://www.devze.com 2023-03-18 18:57 出处:网络
I\'m开发者_StackOverflow社区 using C#, Windows Forms, Net 2.0. I\'m using SHGetImageList to get the system image list with, let\'s say, SHIL_JUMBO parameter and get large 256x256 images on Windows 7.

I'm开发者_StackOverflow社区 using C#, Windows Forms, Net 2.0.

I'm using SHGetImageList to get the system image list with, let's say, SHIL_JUMBO parameter and get large 256x256 images on Windows 7.

[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;
}

I'm also using

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

to set the system image list to my listview, and

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;
}

to get the icon index of different files/folders loaded in the listview.

Everything works fine, except I get large 256 icons even for movie or image files, where I would expect a thumbnail (preview of the image/movie), like in Windows Explorer.

How can I get the thumbnails, not the icons for files that are displayed as thumbnails in Windows Explorer?


In Windows Vista and above you can use IThumbnailProvider interface.

There is a wraper for that in Windows API Code Pack.

For XP there is different interface, see this: http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Thumbnail_Extraction/Thumbail_Tester_Code_zip_ThumbnailTester/ThumbnailCreator_cs.asp

Obviously, you must decide which files will use system image list icons and which will use thumbnails.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号