C#实现获取文件夹中的图标资源
我可以帮助你实现一个C#程序,用于获取文件夹中的图标资源。以下是一个简单的示例代码,它演示了如何使用 System.Drawing 命名空间中的类来获取文件夹和文件的图标。
首先,你需要确保你的项目引用了 System.Drawing 程序集。你可以在项目文件中添加以下引用:
<ItemGroup>
<Reference Include="System.Drawing" />
</ItemGroup>
接下来是完整的代码示例:
using System;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
class Program
{
[DllImport("Shell32.dll")]
private static extern int SHGetFileInfo(
string pszPath,
uint dwFileAttributes,
ref SHFILEINFO psfi,
uint cbFileInfo,
uint uFlags);
private const uint SHGFI_ICON = 0x100;
private const uint SHGFI_LARGEICON = 0x0; // Large icon
private const uint SHGFI_SMALLICON = 0x1; // Small icon
[StructLayout(LayoutKind.Sequential