Page 1 of 1

Better Way Of Handling CreateImageMenu() Images

Posted: Sun Jan 20, 2013 6:15 am
by Blankname
Currently the form designer generates code like this for handling images for a image menu.

Code: Select all

UsePNGImageDecoder()

Img_0 = LoadImage(#PB_Any,"C:\Users\Admin\Desktop\Editor\Icon\Open.png")

MenuItem(#MenuItem_2,"Open", ImageID(Img_0))
The problem is you have to distribute the icons with your program, and in the same directory hard coded into the application. Which is highly unconventional. So I think this should be changed (hopefully before 5.10 release). I have outlined example below of how to pack the icons with the executable itself.

Code: Select all

DataSection
  Image1: IncludeBinary "Icon\Open.png"
  Image2: IncludeBinary "Icon\Save.png"
EndDataSection

UsePNGImageDecoder()
CatchImage(1, ?Image1)
CatchImage(2, ?Image2)

MenuItem(#MENU_1, "Open", ImageID(1))
MenuItem(#MENU_2, "Save", ImageID(2))
This way your menu's can have icons, while also having a single .exe without any trailing data. It would be also nice if you are opening icons with the form designer in the same folder as the .pbf file. That it resolves paths to "Folder\Image.png" so you don't have to keep messing with the source each time you want to compile from a different location on your machine (see example above).

Also note: You are missing spaces in the following functions.
MenuItem(#MenuItem_2,<here>"Open", ImageID(Img_0))
LoadImage(#PB_Any,<here>"C:\Users\Admin\Desktop\Editor\Icon\Open.png")

Re: Better Way Of Handling CreateImageMenu() Images

Posted: Sun Jan 20, 2013 10:18 am
by luciano
There is an "Image Manager" in Form Designer, there you can select many image options and of course you can catch all the images that you want to be embedded in the exe file.

Image

Re: Better Way Of Handling CreateImageMenu() Images

Posted: Mon Jan 21, 2013 6:28 am
by Blankname
luciano wrote:There is an "Image Manager" in Form Designer, there you can select many image options and of course you can catch all the images that you want to be embedded in the exe file.

Image
I was unaware of this :mrgreen:

P.S. CatchImage? | PBAny? => CatchImage | PBAny (the question marks are quite un-needed)