此文记录的是修改文件夹图片的工具类。
/*** 文件夹图标工具类 Austin Liu 刘恒辉 Project Manager and Software Designer E-Mail: lzhdim@163.com Blog: http://lzhdim.cnblogs.com Date: 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; } } }
![]() |
Austin Liu 刘恒辉
Project Manager and Software Designer E-Mail:lzhdim@163.com Blog:https://lzhdim.cnblogs.com 欢迎收藏和转载此博客中的博文,但是请注明出处,给笔者一个与大家交流的空间。谢谢大家。 |
分类:
【153】C#小函数类推荐
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了