Restored from previous forum. Originally posted by freak.
I wrote 2 little procedures for a quick way to handle PanelGadgets with Images.
Here we go...
Code: Select all
;===============================================================================
; Enable Images for a Panel Gadget
; It can be enabled for as many PanelGadgets as needed
; MaxItems is the maximum number of Items your PanelGadget will have.
; If this returns 0, no Images can be added to the Panel
Procedure EnablePanelImages(Gadget, MaxItems)
Protected hIml
hIml = ImageList_Create_(16, 16, #ILC_COLOR32|#ILC_MASK, MaxItems, MaxItems)
If hIml
SendMessage_(GadgetID(Gadget), #TCM_SETIMAGELIST, 0, hIml)
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
; Add an Image to a Panel Item
; You can call this Function again for the same Item, to set a new Image.
Procedure SetPanelImage(Gadget, Position, ImageID)
Protected hIml, pitem.TC_ITEM
hIml = SendMessage_(GadgetID(Gadget), #TCM_GETIMAGELIST, 0,0)
pitem\mask = #TCIF_IMAGE
SendMessage_(GadgetID(Gadget), #TCM_GETITEM, Position, @pitem)
If pitem\iImage = 0
pitem\iImage = ImageList_AddIcon_(hIml, ImageID)
Else
pitem\iImage = ImageList_ReplaceIcon_(hIml, pitem\iImage, ImageID)
EndIf
SendMessage_(GadgetID(Gadget), #TCM_SETITEM, Position, @pitem)
EndProcedure
;===============================================================================
;- Code Example
;===============================================================================
; Load needed Icons (change the Path for your PB dir)
LoadImage(0, "C:\Program Files\PureBasic\Examples\Sources\Data\CdPlayer.ico")
LoadImage(1, "C:\Program Files\PureBasic\Examples\Sources\Data\NewProject.ico")
LoadImage(2, "C:\Program Files\PureBasic\Examples\Sources\Data\SaveProject.ico")
#Panel = 1
; Create Window
OpenWindow(0,0,0,300,300, "Panel Images",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
; Create Panel
PanelGadget(#Panel, 20, 20, 260, 260)
AddGadgetItem(#Panel, 0, "Item0")
AddGadgetItem(#Panel, 1, "Item1")
AddGadgetItem(#Panel, 2, "Item2")
CloseGadgetList()
; Enable Images for this Panel (only 3 Items)
If EnablePanelImages(#Panel, 3)
; Add the loaded Icons to the Panel Items
SetPanelImage(#Panel, 0, ImageID(0))
SetPanelImage(#Panel, 1, ImageID(1))
SetPanelImage(#Panel, 2, ImageID(2))
EndIf
; Wait for Quit
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
;===============================================================================
Timo