Sharpshell を使用して、pdf および xlsx アイコンを変更しています。ほとんどの場合は問題なく動作しますが、黒いアイコンが表示されることがあります。エクスプローラーを更新または再起動しても、影響はありません。
さらに、特定のアイコン ビューでは正常に動作します。たとえば、詳細、コンテンツでは正常に動作しますが、中型アイコンやタイルでは正常に動作しません。また、アイコンはサーバー マネージャー ツールで正常に機能します。
もう 1 つ、黒いアイコンのファイルの名前を変更すると、正しいアイコンがすぐに表示されます。
これはコードです:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using SharpShell.SharpIconHandler;
using SharpShell.Attributes;
using SharpShell.Configuration;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using SharpShell.Diagnostics;
using SharpShell.Interop;
namespace IconHandlerTry2
{
[ComVisible(true)]
[COMServerAssociation(AssociationType.ClassOfExtension, ".pdf", ".xlsx")]
public class Class1 : SharpIconHandler
{
/// <summary>
/// Gets the icon.
/// </summary>
/// <param name="smallIcon">if set to <c>true</c> provide a small icon.</param>
/// <param name="iconSize">Size of the icon.</param>
/// <returns>
/// The icon for the file.
/// </returns>
protected override Icon GetIcon(bool smallIcon, uint iconSize)
{
string prefix = "C:\\Windows\\IconsForYou\\";
string filename = SelectedItemPath;
string iconFileName;
string[] splits = filename.Split('.');
string extension = splits[splits.Length - 1];
if (extension == "pdf")
iconFileName = prefix + "pdfDefault.ico";
else if (extension == "xlsx")
iconFileName = prefix + "xlsxDefault.ico";
else
iconFileName = prefix + "default.ico";
Icon icon = new Icon(iconFileName);
// Return the icon with the correct size. Use the SharpIconHandler 'GetIconSpecificSize'
// function to extract the icon of the required size.
return GetIconSpecificSize(icon, new Size((int)iconSize, (int)iconSize));
}
}
}
これはよりシンプルなバージョンです。私は何百ものアイコンに取り組んでいます。誰か提案はありますか?
編集:アイコンがランダムに割り当てられていることがわかりました。アイコン キャッシュをクリアすると、ランダムなアイコンが表示されます。何もない場合もあるので、真っ黒か真っ白になります。サーバーマネージャーツールでも同じことが起こっています。助けてください!