Add Images to a PanelGadget

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Add Images to a PanelGadget

Post by BackupUser »

Code updated For 5.20+

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

;===============================================================================
Maybe it's usefull to somebody...

Timo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Manolo.

Thanks freak,
Is beautifull this. But... more work for me, because I liked and will need more time for "Pink and Beautifulles" my tab panels.

Regards :evil:

Manolo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Revolver.

Thanks freak! This is great stuff
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Inner.

ta, was just about to ask how to do this a few secs ago, you must have read my mind .
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

> you must have read my mind

Yes I HAVE :evil:

:)
Timo



http://freak.coolfreepages.com/
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Henrik.

Me Like's very much ;o)
Thanks Freak..

Henrik
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Nice tip :).

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TerryHough.
Originally posted by freak
Maybe it's usefull to somebody...
This is at least the second time you have posted a tip that I found extremely useful. Many thanks and keep up your good work!

Terry
Post Reply