欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > 文件夹图标工具类 - C#小函数类推荐

文件夹图标工具类 - C#小函数类推荐

2025/9/19 6:27:18 来源:https://blog.csdn.net/lzhdim/article/details/141875769  浏览:    关键词:文件夹图标工具类 - C#小函数类推荐

       此文记录的是修改文件夹图片的工具类。

/***文件夹图标工具类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;}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com