此文记录的是修改文件夹图片的工具类。
/***文件夹图标工具类Austin Liu 刘恒辉Project Manager and Software DesignerE-Mail: lzhdim@163.comBlog: http://lzhdim.cnblogs.comDate: 2024-01-15 15:18:00使用方法:FolderUtil.SetFolderIcon(dirPath, iconFilePath);***/namespace Lzhdim.LPF.Utility
{using System;using System.Runtime.InteropServices;/// <summary>/// 文件夹图标工具类/// </summary>public class FolderUtil{/// <summary>/// 设置文件夹图标/// </summary>/// <param name="dirPath">文件夹路径</param>/// <param name="strFile">图标文件路径</param>public static void SetFolderIcon(string dirPath, string filePath){LPSHFOLDERCUSTOMSETTINGS FolderSettings = new LPSHFOLDERCUSTOMSETTINGS();FolderSettings.dwMask = 0x10;FolderSettings.pszIconFile = filePath;FolderSettings.iIconIndex = 0;//UInt32 FCS_READ = 0x00000001;UInt32 FCS_FORCEWRITE = 0x00000002;UInt32 FCS_WRITE = FCS_FORCEWRITE;string pszPath = dirPath;UInt32 HRESULT = SHGetSetFolderCustomSettings(ref FolderSettings, pszPath, FCS_WRITE);}[DllImport("Shell32.dll", CharSet = CharSet.Auto)]private static extern UInt32 SHGetSetFolderCustomSettings(ref LPSHFOLDERCUSTOMSETTINGS pfcs, string pszPath, UInt32 dwReadWrite);[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]private struct LPSHFOLDERCUSTOMSETTINGS{public UInt32 dwSize;public UInt32 dwMask;public IntPtr pvid;public string pszWebViewTemplate;public UInt32 cchWebViewTemplate;public string pszWebViewTemplateVersion;public string pszInfoTip;public UInt32 cchInfoTip;public IntPtr pclsid;public UInt32 dwFlags;public string pszIconFile;public UInt32 cchIconFile;public int iIconIndex;public string pszLogo;public UInt32 cchLogo;}}
}