Better Way Of Handling CreateImageMenu() Images

You need some new stunning features ? Tell us here.
Blankname
Enthusiast
Enthusiast
Posts: 120
Joined: Sun Oct 14, 2012 9:11 am

Better Way Of Handling CreateImageMenu() Images

Post 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")
luciano
Enthusiast
Enthusiast
Posts: 151
Joined: Wed Mar 09, 2011 8:25 pm

Re: Better Way Of Handling CreateImageMenu() Images

Post 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
Blankname
Enthusiast
Enthusiast
Posts: 120
Joined: Sun Oct 14, 2012 9:11 am

Re: Better Way Of Handling CreateImageMenu() Images

Post 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)
Post Reply