Get the 48×48 or 256×256 icon of a file on Windows
来源:互联网 发布:怎么看淘宝收货时间 编辑:程序博客网 时间:2024/06/07 02:38
Getting the 16×16 and 32×32 icons on Windows is relatively easy and is often as simple as one call to ExtractIconEx.However, getting the extra large (48×48) and jumbo (256×256) icons introduced respectively by XP and Vista is slighly more complex. This is normally done by:Getting the file information, in particular the icon index, for the given file using SHGetFileInfoRetrieving the system image list where all the icons are storedCasting the image list to an IImageList interface and getting the icon from thereBelow is the code I’m using in Appetizer to retrieve the extra large icon. If needed it can easily be adapted to get the jumbo icon.Update: To do the same thing in C#, see the link in the comments below.view sourceprint?
01.#include <shlobj.h>02.#include <shlguid.h>03.#include <shellapi.h>04.#include <commctrl.h>05.#include <commoncontrols.h>06. 07.// Get the icon index using SHGetFileInfo08.SHFILEINFOW sfi = {0};09.SHGetFileInfo(filePath, -1, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX);10. 11.// Retrieve the system image list.12.// To get the 48x48 icons, use SHIL_EXTRALARGE13.// To get the 256x256 icons (Vista only), use SHIL_JUMBO14.HIMAGELIST* imageList;15.HRESULT hResult = SHGetImageList(SHIL_EXTRALARGE, IID_IImageList, (void**)&imageList);16. 17.if (hResult == S_OK) {18.// Get the icon we need from the list. Note that the HIMAGELIST we retrieved19.// earlier needs to be casted to the IImageList interface before use.20.HICON hIcon;21.hResult = ((IImageList*)imageList)->GetIcon(sfi.iIcon, ILD_TRANSPARENT, &hIcon);22. 23.if (hResult == S_OK) {24.// Do something with the icon here.25.// For example, in wxWidgets:26.wxIcon* icon = new wxIcon();27.icon->SetHICON((WXHICON)hIcon);28.icon->SetSize(48, 48);29.}30.}
转载自 http://pogopixels.com/blog/getting-the-48x48-or-256x256-icon-of-a-file-on-windows/
0 0
- Get the 48×48 or 256×256 icon of a file on Windows
- get the owner of a file
- Displaying the 'Properties' of a file or folder.
- the diary of how to get a random word within a file
- Get the directory of one php file
- Get some information of the file
- A list of books on general-purpose algorithms for the practical programmer (or 'software engineer')
- Get the equivalent of GetModuleFileName on Linux
- Use Flex and JavaScript to get the full path of a local File
- 【软件自动化测试 - VBScript 5】== Get the recently createed Folder or a File in a Parent Folder
- XML Declaration must be on the very begining of a XML file
- sorting data based on the value in second column of a file
- How to get the data from a cell when I click on the GridButtonColumn of the same row
- [INS-41107]eth0 selected for one or more of the public or private interfaces is not on a shared subn
- Get the Mime Type from a File
- Get the Mime Type from a File
- Shortcut to solve the lacking of stdint.h header file on Windows
- How to remove the icon of a WPF window
- JAVA_形象生动的单例模式总结
- 斯诺登泄露文件:英美联手监听德国电信
- 使用setCustomView建立标题居中的自定义ActionBar
- Linker error
- C/C++ 使用宏在编译期计算可变参数个数
- Get the 48×48 or 256×256 icon of a file on Windows
- Cocos2d-x3.2 iOS下开启多点触控
- CentOS 打包压缩文件 zip 命令详解
- android平板上EditText总是自动弹出输入法问题
- webview setting movie path:程序崩溃
- 数据结构之线性表4单链表(静态单链表)
- linux文件系统与根文件系统
- SVN框架模式和运行分析理解 适合初学者
- 网络请求生成图片