使用纯.NET代码获取Windows驱动器或文件夹的系统图标 [英] Get the system's icon of a windows drive or folder with pure .NET Code

查看:124
本文介绍了使用纯.NET代码获取Windows驱动器或文件夹的系统图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是初学者,我想知道如何获得带有纯.NET代码的Windows驱动器或文件夹的系统图标 - 我目前正在考虑单行或类似的东西。

我已经尝试过这个:



I am a beginner and I wonder how could I get the system's icon of a windows drive or folder with pure .NET Code - I am currently thinking of a one-liner or something like that.
I have tried already this:

this.Icon=System.Drawing.Icon.ExtractAssociatedIcon(@"C:\");
this.Icon=System.Drawing.Icon.ExtractAssociatedIcon(@"C:\Windows");





两者都因FileNotFound错误而失败。我可以将文件夹转换为文件,然后提取图标并将其转换回来吗?或者需要此功能的其他参数?

我搜索一个没有很多外部函数的紧凑方式来提取文件夹图标。任何想法?



如果需要那些外部API,任何人都有一个准备好的类,可用于从文件夹,文件和驱动器读取图标并放入列表视图。我的意思是一个防错的类,适合一次读取数百个图标并在listView中显示它们?什么也没找到。微软的MSDN代码我已经看过并研究过但它没有工作(没有图标显示)和OutOfMemory Exception在大于507的图标数上发生。



无法解决到目前为止,这只有来自文件本身的图标。

文件图标的质量也非常低,如果

我使用下面的代码,则不是正确的窗口图标:



Both fails with a FileNotFound Error. Can I convert the folder to file and then extract the icon and the convert it back? Or needs this function other parameters?
I search for a compact way without many external functions to extract a folder icon. Any ideas?

If needed those external API's does anyone have a class on the ready which could be used to read icons from folders, files and drives and put into a listview. I mean a class which is error-proof and suitable to read hundreds of icons at once and displays them in the listView? Have nothing found yet. Microsoft's MSDN code I have seen and studied but it didn't worked (no icons displayed) and OutOfMemory Exception occures on a icon count larger than 507.

Could not solve this yet so far got only icons from Files itself.
File icons have also very low quality and are not right windows icons if
I use this code below:

this.Icon=System.Drawing.Icon.ExtractAssociatedIcon(@"C:\myfile.txt");



找不到另一个完全正常的代码或文件夹和驱动器的工具。


Found not another fully working code or tool yet for Folders and Drives.

推荐答案

AFAIK,你不能用纯.NET做 - 你需要使用DLLImport:http://support2.microsoft.com/?kbid=319350 [ ^ ]
AFAIK, you can't do it in pure .NET - you need to use a DLLImport: http://support2.microsoft.com/?kbid=319350[^]


这篇关于使用纯.NET代码获取Windows驱动器或文件夹的系统图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆