Code: Alles auswählen
Procedure.l GetExtensionIcon(extension.s, Size.l)
Protected Info.SHFILEINFO, StandardIcon.l, flags.l
StandardIcon = 0
If Size = 0
flags = #SHGFI_USEFILEATTRIBUTES | #SHGFI_ICON | #SHGFI_SMALLICON
Else
flags = #SHGFI_USEFILEATTRIBUTES | #SHGFI_ICON | #SHGFI_LARGEICON
EndIf
If SHGetFileInfo_("." + extension, #FILE_ATTRIBUTE_NORMAL, @Info.SHFILEINFO, SizeOf(SHFILEINFO), flags)
StandardIcon = Info\hIcon
Else
If Size = 0
ExtractIconEx_("shell32.dll", 0, 0, @StandardIcon, 1)
Else
ExtractIconEx_("shell32.dll", 0, @StandardIcon, 0, 1)
EndIf
EndIf
ProcedureReturn StandardIcon
EndProcedure
; Small example code
extension.s = "txt"
If OpenWindow(0, 0, 0, 100, 100, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "DefaultIcon for " + extension)
If CreateGadgetList(WindowID())
ExtIcon = GetExtensionIcon(extension, 1)
ImageGadget(0, 10, 10, 32, 32, ExtIcon)
Repeat
Until WaitWindowEvent() = #PB_EventCloseWindow
EndIf
EndIf
DestroyIcon_(ExtIcon)
End
zurück - halt das Icon, dass einem der Explorer anzeigt.
Das Icon ist entweder Small oder Big, je nachdem, ob man bei der
Size 0 oder 1 angibt.
Das Icon sollte man nach der Benutzung mit DestroyIcon_(IconHandle) wieder freigeben.