这里是我想要的功能:
string getIconPath(string folderPath) {
SHFILEINFO shinfo = new SHFILEINFO();
Win32.SHGetFileInfo(folderPath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), (int)0x1000);
return shinfo.szDisplayName
}
这里是SHFILEINFO结构和Win32类实现:
[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
};
class Win32
{
[DllImport("shell32.dll")]
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
}
你要我们找到你的PC上的路径...? – MarioDS 2014-10-05 18:47:57
不,我需要知道如何在C#中找到文件夹图标路径,就像我有文件夹路径:C:\ ... \ a有一个自定义的图标,我从D:\ .... \ sdfa之前设置。 ico,我需要一个像字符串geticonpath(@“c:\ ... \ a”)的函数,它给了我“D:\ ... \ sdfa.ico” – user4111079 2014-10-05 19:33:01
您不能在您存储位置正在设置图像并在以后使用这些信息? – pasty 2014-10-05 21:03:06