Hi nilslueders
Probiers mal mit der Klasse:
Option Strict On
Imports System
Imports System.Drawing
Imports System.Runtime.InteropServices
Class IconSpy
' API-Funktionen
Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias _
"ExtractAssociatedIconA" ( _
ByVal hInst As Integer, ByVal lpIconPath As String, ByRef lpiIcon As _
Integer) As IntPtr
Private Declare Function ExtractIconEx Lib "shell32.dll" Alias _
"ExtractIconExA" ( _
ByVal lpszFile As String, ByVal nIconIndex As Integer, ByRef phiconLarge As _
Integer, _
ByRef phiconSmall As Integer, ByVal nIcons As Integer) As Integer
' API zum Ermitteln des Dateisymbols.
Private Declare Ansi Function SHGetFileInfo Lib "shell32.dll" (ByVal pszPath _
As String, ByVal dwFileAttributes As Integer, ByRef psfi As ShFileInfo, _
ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As IntPtr
' Wird zum ermitteln des Dataeisymbols benötigt.
Private Structure ShFileInfo
Friend hIcon As IntPtr
Friend iIcon As Integer
Friend dwAttributes As Integer
Friend szDisplayName As String
Friend szTypeName As String
End Structure
' die Anzahl der Symbole in der Datei.
Private i32Icons As Integer
' der Pfad der Datei mit den Symbolen
Private strFilePath As String
Sub New(ByVal FilePath As String)
i32Icons = ExtractIconEx(FilePath, -1, 0, 0, 0)
strFilePath = FilePath
End Sub
ReadOnly Property Icons() As Integer
Get
Return i32Icons
End Get
End Property
Function GetIcon(ByVal Index As Integer) As Icon
Return Icon.FromHandle(ExtractAssociatedIcon(0, strFilePath, Index))
End Function
' Ermittelt das Symbol einer Datei.
Shared Function GetFileIcon(ByVal Path As String) As Icon
Dim hImgSmall As IntPtr ' Handle zur System-Image-List
Dim ShInfo As ShFileInfo
Try
ShInfo = New ShFileInfo
ShInfo.szDisplayName = New String(NullChar, 260)
ShInfo.szTypeName = New String(NullChar, 80)
hImgSmall = SHGetFileInfo(Path, 0, ShInfo, Marshal.SizeOf(ShInfo), &H100 _
Or &H1)
Return Icon.FromHandle(ShInfo.hIcon)
Catch
ShInfo.szDisplayName = New String(NullChar, 260)
End Try
End Function
End Class Anwendung:Dim FileIcon As Icon = GetFileIcon("X:\abc.exe") demn?chst Online: SnofWare.de |