Rubrik: Grafik und Font · Bilder & Icons | VB-Versionen: VB4, VB5, VB6 | 04.04.01 |
Icons einer Anwendung/DLL extrahieren Hier wird gezeigt, wie man die Icons einer Anwendung bzw. einer DLL extrahieren und anzeigen kann. | ||
Autor: LonelySuicide666 | Bewertung: | Views: 21.626 |
www.vbapihelpline.de | System: Win9x, WinNT, Win2k, WinXP, Win7, Win8, Win10, Win11 | Beispielprojekt auf CD |
Viele Anwendungen oder DLLs beinhalten nicht nur ein einziges ICON (Bildsymbol), sondern meist eines in der Größe 16x16 (small) und eines in der Größe 32x32 (large). Oftmals sindfür eine Anendung noch weitere zusätzliche Icons gespeichert. Möchten Sie z.B. ein Programm erstellen, welches alle Icons einer Anwendung oder DLL extrahiert, so ist der nachfolgende Tipp genau der richtige für Sie.
' zunächst die benötigten API-Deklarationen Private Declare Function DestroyIcon Lib "user32.dll" ( _ ByVal hIcon As Long) As Long Private Declare Function ExtractIconEx Lib "shell32.dll" _ Alias "ExtractIconExA" ( _ ByVal lpszFile As String, _ ByVal nIconIndex As Long, _ phiconLarge As Long, _ phiconSmall As Long, _ ByVal nIcons As Long) As Long Private Declare Function DrawIconEx Lib "user32.dll" ( _ ByVal hdc As Long, _ ByVal xLeft As Long, _ ByVal yTop As Long, _ ByVal hIcon As Long, _ ByVal cxWidth As Long, _ ByVal cyWidth As Long, _ ByVal istepIfAniCur As Long, _ ByVal hbrFlickerFreeDraw As Long, _ ByVal diFlags As Long) As Long Const DI_COMPAT = &H4 Const DI_DEFAULTSIZE = &H8 Const DI_IMAGE = &H2 Const DI_MASK = &H1 Const DI_NORMAL = &H3
Die Funktion ExtractIconEx liefert einerseits die Handles der Icons (large und small) zurück, zum anderen läßt sich über die Funktion aber auch die Anzahl vorhandenener Icons ermitteln.
' Liefert die Anzahl der vorhandenen Icons einer ' EXE- oder DLL-Datei Public Function GetIconCount(ByVal Filename As String) _ As Integer GetIconCount = ExtractIconEx(Filename, -1, 0&, 0&, 0&) End Function
Der nachfolgende Code ermittelt die Handles für das normale Icon (large, 32x32) und des kleinen Icons (small, 16x16).
' Handle der Icons (large und small) Dim LargeIconArray(0) As Long Dim SmallIconArray(0) As Long ExtractIconEx Filename, IconIndex, LargeIconArray(0), _ SmallIconArray(0), 1
Anzeigen der Icons
Um die beiden Icons nun in einer PictureBox anzuzeigen, gehen Sie wie folgt vor:
' Zeichnet das "Große Icon" With LargeIconPic .Width = Screen.TwipsPerPixelX * 32 .Height = Screen.TwipsPerPixelY * 32 .Cls DrawIconEx .hdc, 0, 0, LargeIconArray(0), _ 32, 32, 0&, 0&, DI_NORMAL .Refresh End With ' Zeichnet das "Kleine Icon" With SmallIconPic .Width = Screen.TwipsPerPixelX * 16 .Height = Screen.TwipsPerPixelY * 16 .Cls DrawIconEx .hdc, 0, 0, SmallIconArray(0), _ 16, 16, 0&, 0&, DI_NORMAL .Refresh End With
Nach getaner Arbeit sollten die Handles wieder freigegeben werden.
' Handle wieder freigeben DestroyIcon LargeIconArray(0) DestroyIcon SmallIconArray(0)
Ermitteln ALLER Icons einer Datei
Der nachfolgende Code ermittelt alle in einer Datei gespeicherten Icons.
' Anzahl Icons Dim nCount As Long nCount = GetIconCount(Filename) ' Handles der Icons Dim LargeIconArray(nCount) As Long Dim SmallIconArray(nCount) As Long ExtractIconEx Filename, 0, LargeIconArray(0), _ SmallIconArray(0), nCount ... ' Handles wieder freigeben For i = 0 To nCount DestroyIcon LargeIconArray(i) DestroyIcon SmallIconArray(i) Next i
Nur large Icon
Ebensogut kann auch nur das Handle des großen Icons ermittelt werden.
' nur "großes Icon" Dim LargeIconArray(0) As Long ExtractIconEx Filename, IconIndex, LargeIconArray(0), 0, 1 ... ' Handle wieder freigeben DestroyIcon LargeIconArray(0)