これはかなり標準的なコードです:
public static System.Windows.Media.Imaging.BitmapSource GetIcon(string Path, int Width = 256, int Height = 256)
{
IShellItem ppsi = null;
IntPtr hbitmap = IntPtr.Zero;
Guid uuid = new Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe");
SHCreateItemFromParsingName(Path, IntPtr.Zero, uuid, ref ppsi);
((IShellItemImageFactory)ppsi).GetImage(new SIZE(Width, Height), SIIGBF.SIIGBF_RESIZETOFIT, ref hbitmap);
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
CD-ROM 上のアイコン (特に WMV) のアイコンを表示しようとする場合を除いて、常に機能します。ダウンロードに時間がかかりますか?または何か... Bitmapsource オブジェクトには「ダウンロード」イベントがあります。しかし、私はコードをステップ実行しましたが、それはヒットしていません。
これは「キャッシング」の問題でもあるようです。しかし、奇妙なことに、CD-Rom のアイコンだけに影響を与えるのですか?