图标处理程序显示黑色图标

时间:2015-06-11 10:15:12

标签: windows shell-extensions sharpshell icon-handler

我正在使用Sharpshell更改我的pdf和xlsx图标。大多数时候它工作正常,但有时它显示黑色图标。刷新或重新启动资源管理器对它没有任何影响。

此外,它在某些图标视图中工作正常 - 例如在详细信息中,内容工作正常,但不在中图标或图块中。此外,图标在服务器管理器工具中正常工作。

还有一件事 - 如果我更改了带有黑色图标的文件的名称,则会立即显示正确的图标。

这是代码:

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));
        }
    }
}

这是更简单的版本。我将处理数百个图标。有没有人有任何建议?

编辑:我现在看到图标是随机分配的。每当我清除图标缓存时,都会显示一些随机图标。有时没有任何东西,所以它变成全黑或白色。服务器管理器工具中也发生了同样的事情。请帮忙!

0 个答案:

没有答案
相关问题