這裏是我想要的功能:
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