Page 1 of 1

Including icons into code

Posted: Mon Mar 12, 2018 11:05 am
by Cezary
Dear forum users,

is there some way to include all program icons into the code? I want to get only one executable file, without any additional icon files, but I can't find how to do that.
Thanks in advance for all suggestions.

Best regards

Re: Including icons into code

Posted: Mon Mar 12, 2018 11:07 am
by Bisonte

Code: Select all

DataSection
MyIcon:
IncludeBinary "MyIconFile.ico"
EndDataSection

CatchImage(#Icon, ?MyIcon)
Work with all images, with ImagePlugin ... like UsePngImageDecoder()...

Re: Including icons into code

Posted: Mon Mar 12, 2018 5:10 pm
by Cezary
You're great!
Thank you.

Re: Including icons into code

Posted: Wed Mar 14, 2018 11:56 pm
by Cezary
Yet another problem:
if I use:

Code: Select all

  ButtonImageGadget(#BtnIdManHdec,
                    ScaleDPIx(20), ScaleDPIy(19),
                    ScaleDPIx(20), ScaleDPIy(14),
                    ImageID(LoadImage(#PB_Any, "ICO/arrow_left.png")))
everything is ok,
but in this case:

Code: Select all

  ButtonImageGadget(#BtnIdManHdec,
                    ScaleDPIx(20), ScaleDPIy(19),
                    ScaleDPIx(20), ScaleDPIy(14),
                    CatchImage(0, ?ArrowLeftIco))
icon on the button disappears after first clickink on it.
What am I doing wrong?
I use PB 5.62 x64 on Linux.

Re: Including icons into code

Posted: Thu Mar 15, 2018 12:12 am
by Bisonte

Code: Select all

ImageID(CatchImage(0, ?ImageLabel))

Re: Including icons into code

Posted: Thu Mar 15, 2018 7:41 am
by Cezary
Thank you again, it works now, but with a little exeption:

Code: Select all

ImageID(CatchImage(#PB_Any, ?ImageLabel))
Thanks!

Re: Including icons into code

Posted: Sun Mar 18, 2018 8:25 pm
by Iordanis
This is my first post. I decided to give PB a try over another competitive product and i created a small exe that opens a form and loads buttons (png files). The program runs but i need to clarify someηting. The code is the following:

Code: Select all

DataSection
  Archive:
  IncludeBinary "icons_48/Archive.png"
  Bank:
  IncludeBinary "icons_48/Bank.png"
  Bsman:
  IncludeBinary "icons_48/businessman.png"
  money:
  IncludeBinary "icons_48/money-bag.png"
  safebox:
  IncludeBinary "icons_48/safebox.png"
  cityscape:
  IncludeBinary "icons_48/cityscape.png"
 
EndDataSection

Procedure MyToolBar()
  
  UsePNGImageDecoder()

  ButtonImageGadget(0, 0, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?Archive)), #PB_Button_Toggle)

  ButtonImageGadget(1, 60, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?Bank)), #PB_Button_Toggle)

  ButtonImageGadget(2, 120, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?bsman)), #PB_Button_Toggle)

  ButtonImageGadget(3, 180, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?money-bag)), #PB_Button_Toggle)

  ButtonImageGadget(4, 240, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?safebox)), #PB_Button_Toggle)

  ButtonImageGadget(5, 300, 0, 60, 60, ImageID(CatchImage(#PB_Any, ?cityscape)), #PB_Button_Toggle)

  

EndProcedure
My question is this.. in order to create an image DO i need to initialise the #image variable?
How does ButtonImageGadget work here if i havent loaded or created an image?

At some point it was complaining that i did not initialise an image and i do not remember what change i made and it stopped. The idea for all this is to include the image in the .app file.

Re: Including icons into code

Posted: Mon Mar 19, 2018 5:36 am
by citystate
technically you have been creating the images with CatchImage() - this command loads an image from memory
ordinarily, I'd load all my images with specific image_numbers, and then assign them to the ButtonImageGadgets by number (this way you can reuse images easily without having to reload them - helps with memory usage too)

Re: Including icons into code

Posted: Tue Mar 27, 2018 7:58 pm
by Iordanis
Thank you. Your answer saved me hours of searching.