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)