Zum Inhalt springen

Empfohlene Beiträge

Geschrieben

Hi,

weiß hier jemand wie man einem Toolbar Button ein Icon zuweisen kann, ohne dass das Icon in einer ImageList ist, also so das ich z.b. den Namen einer Datei nehme und er das Icon dieser Datei nimmt...?

Danke im voraus

Geschrieben

... oder ich formuliere mein frage mal etwas um... wie kann ich das Icon aus einer Compilierten EXE datei 'herausholen'... also das machen was man unter den Eigenschaften eines Shortcuts als Change Icon findet?

Geschrieben

Also möchtest Du einem ToolBarButton ein Icon aus einer EXE-Datei zuweisen?

Geschrieben

AFAIK geht das nicht. Eine Toolbar benötigt Icons in einer ImageList.

Geschrieben

Nachtrag: Wenn Du Icons während der Entwicklungszeit in Deine ToolBar hinzufügen möchtest, dann kannst Du die Icons mit Resource Hacker (zu finden als Freeware auf der aktuellen ct) aus den EXE- und DLL-Dateien extrahieren.

  • 4 Wochen später...
Geschrieben

sollte es jemanden interessieren:


Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias _
"SHGetFileInfoA" (ByVal pszPath As Any, ByVal _
dwFileAttributes As Long, psfi As ShellFileInfoType, ByVal _
cbFileInfo As Long, ByVal uFlags As Long) As Long

Private Type ShellFileInfoType
hIcon As Long
iIcon As Long
dwAttributes As Long
szDisplayName As String * 260
szTypeName As String * 80
End Type

Private Declare Function OleCreatePictureIndirect Lib "oleaut32.dll" (pDicDesc As IconType, riid As CLSIdType, ByVal fown As Long, lpUnk As Object) As Long

Private Type CLSIdType
id(16) As Byte
End Type

Private Type IconType
cbSize As Long
picType As PictureTypeConstants
hIcon As Long
End Type

Private Const Small = &H101
Dim i As Integer

Private Sub Command1_Click()
cd.ShowOpen
BuildButton cd.FileName, "test", "i" & i
i = i + 1
End Sub


Public Function BuildButton(strImageKey As String, strTooltipText As String, intNr As String)
'sollen Buttons in de Toolbar während der Laufzeit erstellt werden, so brauch man diese funktion
Dim imgX As ListImage
Dim btnX As Button

If strImageKey = "tbrSeparator" Then
Set btnX = Toolbar1.Buttons.Add(, , , tbrSeparator)
Else
ImageList2.ListImages.Add , intNr, LoadIcon(Small, cd.FileName)
Toolbar1.ImageList = ImageList2
Set btnX = Toolbar1.Buttons.Add(, intNr, , tbrDefault, intNr)
btnX.ToolTipText = strTooltipText
btnX.Description = btnX.ToolTipText
End If
End Function

Private Function LoadIcon(Size&, File$) As IPictureDisp

Dim Result&
Dim Unkown As IUnknown
Dim Icon As IconType
Dim CLSID As CLSIdType
Dim ShellInfo As ShellFileInfoType

Call SHGetFileInfo(File, 0, ShellInfo, Len(ShellInfo), Size)

Icon.cbSize = Len(Icon)
Icon.picType = vbPicTypeIcon
Icon.hIcon = ShellInfo.hIcon
CLSID.id(8) = &HC0
CLSID.id(15) = &H46
Result = OleCreatePictureIndirect(Icon, CLSID, 1, Unkown)
Set LoadIcon = Unkown

End Function

Private Sub Form_Load()
i = 1
End Sub
[/PHP]

... benötigt wird: Button(Command1), ImageList (ImageList2), Toolbar (Toolbar1), Commondialog (cd)

Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde Dich hier an.

Jetzt anmelden

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...