Hi,
ich möchte gerne eine Methode, Klasse oder Modul haben, das mir in jedem Fall ein Icon zu einer Datei zurückgibt. Oder wenn es Dateien ohne Endung sind, ein Default Icon wie es der Explorer anzeigt.
Ich bin verzweifelt, wenn ich die .Net 2.0 Methode "Icon.ExtractAssociatedIcon" nutze dann kackt mir die Anwenung ab.
Wenn ich diesen Code genutzt habe, hat es bei php Dateien die mit Dreamweaver verknüpft waren ärger gegeben.
Imports Microsoft.Win32
Module gfx
#Region "DIE BENÖTIGTEN API DEKLERATIONEN"
<Runtime.InteropServices.DllImport("shell32.dll")> _
Public Function ExtractIconEx(ByVal szFileName As String, ByVal nIconIndex _
As Integer, ByVal phiconLarge As IntPtr(), ByVal phiconSmall As IntPtr(), _
ByVal nIcons As System.UInt32) As System.UInt32
End Function
#End Region
' GetIcons()(0) gibt das große Symbol zurück und GetIcons()(1) das kleine
Public Function GetIconsFromFile(ByVal pExtension As String, ByVal pPath As _
String, ByVal pFilename As String) As IntPtr()
Dim key As RegistryKey
Dim Icos(2) As IntPtr
Dim Symbolgross(1) As IntPtr
Dim Symbolklein(1) As IntPtr
Dim str As String = ""
Dim temp As String = ""
Dim index2 As Integer = 0
' Übergebene Parameter in ein Standardformat bringen
If Not pPath.EndsWith("\") Then
pPath += "\"
End If
If pFilename.EndsWith(pExtension) Then
pFilename = pFilename.Remove(pFilename.Length - pExtension.Length, _
pExtension.Length)
End If
' Wenn es keinen Eintrag in der Registry für die Endung gibt,
' kommt catch ins Spiel (z.b.: bei .EXE und .LNK Dateien)
Try
key = Registry.ClassesRoot.OpenSubKey(pExtension, True)
str = key.GetValue(Nothing).ToString()
key = Registry.ClassesRoot.OpenSubKey(str & "\DefaultIcon", True)
str = key.GetValue(Nothing).ToString()
temp = str
index2 = 1
While (True)
temp = temp.Remove(0, temp.Length - index2)
temp = temp.Remove(1, index2 - 1)
If temp.Equals(",") Then
Exit While
End If
temp = str
index2 += 1
End While
temp = str.Remove(0, str.Length - index2 + 1)
ExtractIconEx(str.Remove(str.Length - index2, index2), Int32.Parse( _
str.Remove(0, str.Length + 1 - index2)), Symbolgross, _
Symbolklein, 1)
Icos(0) = Symbolgross(0)
Icos(1) = Symbolklein(0)
Catch ex As Exception
If pExtension.ToUpper().Equals(".EXE") Or pExtension.ToUpper( _
).Equals(".LNK") Then
If (ExtractIconEx(pPath & "\" & pFilename & pExtension, 0, _
Symbolgross, Symbolklein, 1) = 0) Then
ExtractIconEx(Environment.SystemDirectory & "\Shell32.dll", _
0, Symbolgross, Symbolklein, 1)
End If
Else
' Wenn es sich um eine unbekannte Endung handelt, dann wähle
' ein Standarticon
ExtractIconEx(Environment.SystemDirectory & "\Shell32.dll", 0, _
Symbolgross, Symbolklein, 1)
End If
Icos(0) = Symbolgross(0)
Icos(1) = Symbolklein(0)
End Try
Return Icos
End Function
End ModuleKönnte mir jemand diebeste Methode nennen, oder die er dafür hällt?!
Danke im vorraus |