Imports System.Drawing Imports System.Runtime.InteropServices Imports Pilz.Win32.Native Namespace Internals Public Class IconExtractor ''' ''' Extrahiert das Icon aus einer Datei oder aus einem Ordner. ''' ''' Hier übergeben Sie den Pfad der Datei von dem das Icon extrahiert werden soll. ''' Bei übergabe von true wird ein kleines und bei false ein großes Icon zurück gegeben. Public Shared Function ExtractIcon(ByVal FilePath As String, ByVal Small As Boolean) As Icon Dim hImgSmall As IntPtr Dim hImgLarge As IntPtr Dim shinfo As New SHFILEINFO If Small Then hImgSmall = LibShell32.SHGetFileInfo(FilePath, 0, shinfo, CUInt(Math.Truncate(Marshal.SizeOf(shinfo))), SHFILEINFO.SHGFI_ICON Or SHFILEINFO.SHGFI_SMALLICON) Else hImgLarge = LibShell32.SHGetFileInfo(FilePath, 0, shinfo, CUInt(Math.Truncate(Marshal.SizeOf(shinfo))), SHFILEINFO.SHGFI_ICON Or SHFILEINFO.SHGFI_LARGEICON) End If Dim icon As Icon Try icon = Icon.FromHandle(shinfo.hIcon) Catch ex As Exception icon = Nothing End Try Return icon End Function End Class End Namespace