开发者

Getting icons of Drives and Directories: Icon.ExtractAssociatedIcon(filePath) doesn't work?

开发者 https://www.devze.com 2023-02-21 06:39 出处:网络
If Icon.ExtractAssociatedIcon(filePath) is 开发者_Python百科the only way to get icons in .NET && if it doesn\'t work for Drives and Directories (does it?) then how do you go about getting the

If Icon.ExtractAssociatedIcon(filePath) is 开发者_Python百科the only way to get icons in .NET && if it doesn't work for Drives and Directories (does it?) then how do you go about getting the icons for them?

In other words, I'd like to

foreach (string driveName in Directory.GetLogicalDrives())
//if (System.IO.Directory.Exists(driveName))
{
    using (System.Drawing.Icon systemIcon = System.Drawing.Icon.ExtractAssociatedIcon(driveName))
    { ... }
}

^ this obviously doesn't work (works only for files)

I'm not sure System.IO.Directory.Exists(file) is the right way for detecting if drives exist as well...


To do this from a .NET application, you will have to P/Invoke the SHGetFileInfo function from the Windows API (it's defined in shell32.dll).

Here is some sample code that shows how to do this: Getting Associated Icons Using C#

0

精彩评论

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

关注公众号