VIsta中的图标提取
为了提取特殊文件夹图标,我正在使用
ExtractIconEx(Environment.SystemDirectory + "\\shell32.dll",ncIconIndex, handlesIconLarge, handlesIconSmall, 1);
这里,我为特殊文件夹(如 MyDocs、MyPictures ..etc)显式传递 nIconIndex 它在 XP 中工作正常,但是在 Vista 中它无法检索正确的图标..它检索黄色文件夹图标..它不应该是这种情况。 任何人都可以帮我解决这个问题..
for extracting special folder icons I'm using
ExtractIconEx(Environment.SystemDirectory + "\\shell32.dll",ncIconIndex, handlesIconLarge, handlesIconSmall, 1);
Here im passing explicitly nIconIndex for special folders like MyDocs,MyPictures ..etc
and its working fine in XP ,however in Vista its not retrieving the correct icons ..there it retrieves yellow folder icons..it should not be the case.
Cn anybody help me on this..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 codeproject 上的 IconLib 库。
Check out the IconLib library at codeproject.
Vista 添加了一个名为 SHGetStockIconInfo 的新 API,但据我所知它不支持我的文档。 但这并不重要,因为您应该使用的方法适用于 XP 和 Vista(当用户选择自定义图标时,您当前的解决方案将不起作用,您只是在硬编码的系统 dll 中查找,这可能随时发生变化)
因此,您应该做的是,获取您感兴趣的 shell 文件夹(SHGetFolderPath 等)的路径或 PIDL,并将该路径/PIDL 传递给 SHGetFileInfo。 SHGetFileInfo 可以给你一个图标句柄,或者系统图像列表的索引。
我不确定这些函数的 .NET 等效项是什么,但您应该能够弄清楚,或者使用 PInvoke
Vista added a new API called SHGetStockIconInfo but it does not support my documents AFAIK. But that does not matter since the method you SHOULD be using works on both XP and Vista (Your current solution will not work when the user has selected a custom icon, you are just looking in hardcoded system dlls, this could change at any point)
So, what you should do is, get the path or PIDL to the shell folder you are interested in (SHGetFolderPath and friends) and pass that path/PIDL to SHGetFileInfo. SHGetFileInfo can give you a icon handle, or the index into the system image list.
I'm not sure what the .NET equivalent for those functions are, but you should be able to figure that out, or use PInvoke
这篇文章是我从 .NET(使用 VB.NET 完成的)在该领域看到的成功的最佳示例。
http://www.codeproject.com/KB/cpp/VbNetExpTree.aspx
我的 $.02 是,由于所需的 COM 互操作级别和 API 的复杂性,在 .NET 中使用 shell API 是非常痛苦的。
The best example I've seen of success in this area from .NET (and it was done with VB.NET) is in this article.
http://www.codeproject.com/KB/cpp/VbNetExpTree.aspx
My $.02 is that working with the shell API is extremely painful from .NET due to the level of COM interop required and the complexity of the API's.