代码之家  ›  专栏  ›  技术社区  ›  Edwin Yip

通过文件扩展名获取扩展名和图标的最快方法?

  •  1
  • Edwin Yip  · 技术社区  · 16 年前

    1. 搜索注册表:

    2. 根据Rob的说法: How to get icon and description from file extension using Delphi?

    将IExtractIcon接口称为“更灵活、更高效”的替代方案。但它建议的顺序是使用IShellFolder接口,然后调用GetUIObjectOf以获取文件的IExtractIcon接口,然后对其调用GetIconLocation and Extract以检索图标的句柄。(但此方法无法读取扩展描述?)

    因为速度非常重要,因为我需要读取系统中所有文件类型的信息。

    3 回复  |  直到 8 年前
        1
  •  5
  •   Jason Williams    16 年前

    最后,在权衡了上述问题后,最好的方法是编写10行代码,尝试所有三种方法,看看哪种方法最快。

        2
  •  2
  •   AMissico    16 年前

    更多,请看 http://support.microsoft.com/kb/319340

    Private Shared _descriptions As New Dictionary(Of String, String)
    
    Private Shared Function CacheDocumentDescription(ByVal extension As String, ByVal description As String) As String
        _descriptions.Add(extension, description)
        DumpCacheDocumentItem(extension, description, "added")
        Return description
    End Function
    
    <Conditional("DbCacheDocument")> _
    Private Shared Sub DumpCacheDocumentItem(ByVal extension As String, ByVal description As String, ByVal category As String)
        Debug.WriteLine(extension & ", " & description, category)
    End Sub
    
    Public Shared Function GetTypeName(ByVal fullPath As String) As String
    
        Dim sExt As String = System.IO.Path.GetExtension(fullPath)
    
        If Len(sExt) = 0 Then
            Return "File"
        End If
    
        If _descriptions.ContainsKey(sExt) Then
            'return cached value
            Return _descriptions.Item(sExt)
        End If
    
        Dim sDocDescription As String = Missico.Shell.ShellFileInfo.TypeName(fullPath)
    
        Return CacheDocumentDescription(sExt, sDocDescription)
    End Function
    
        3
  •  0
  •   scaryman    13 年前

    我参加这个聚会有点晚了,但我要把p/invoke.net链接留在这里,链接到SHGetFileInfo- http://www.pinvoke.net/default.aspx/shell32/SHGetFileInfo.html

    推荐文章