Page 1 of 1

[SOLVED] Compiling an exe with multiple icons in it.

Posted: Mon Sep 11, 2023 4:24 pm
by mikejs
Hi all,

Is it possible use PB to compile an exe such that we embed multiple icons in it? i.e. not just multiple versions of the same icon at different sizes/colour depths, but multiple different icons, that can be referred to by index when creating shortcuts.

In the compiler options, there is just a choice of .ico file. And it seems that I can't put multiple icons in a single .ico - at least, IcoFX won't let me create multiple icons with the same size and colour depth in a single .ico file.

It's clearly doable though, - purebasic itself has multiple icons in the exe for the IDE.

If I can't do this natively presumably I need to not do an icon at all in PB, and do something with the SDK tools (rc.exe?) after compiling?

Re: Compiling an exe with multiple icons in it.

Posted: Mon Sep 11, 2023 5:18 pm
by AZJIO

Code: Select all

; CompilerIf  #PB_Compiler_OS = #PB_OS_Linux
; 	; https://www.purebasic.fr/english/viewtopic.php?p=531374#p531374
; 	ImportC ""
; 		gtk_window_set_icon(a.l,b.l)
; 	EndImport
; CompilerEndIf

UseGIFImageDecoder() ; + 15 kb
; UsePNGImageDecoder() ; png? + 150 kb

DataSection
	IconTitle:
	IncludeBinary "images" + #PS$ + "title.gif"
	link:
	IncludeBinary "images" + #PS$ + "link.gif"
	calculate:
	IncludeBinary "images" + #PS$ + "calculate.gif"
	copy:
	IncludeBinary "images" + #PS$ + "copy.gif"
	insert:
	IncludeBinary "images" + #PS$ + "insert.gif"
	set:
	IncludeBinary "images" + #PS$ + "set.gif"
EndDataSection

CatchImage(0, ?IconTitle)
CatchImage(3, ?link)
CatchImage(1, ?calculate)
CatchImage(2, ?copy)
CatchImage(4, ?insert)
CatchImage(5, ?set)

Debug  ImageID(0)
Debug  ImageID(1)
Debug  ImageID(2)
Debug  ImageID(3)
Debug  ImageID(4)
Debug  ImageID(5)

; CompilerIf  #PB_Compiler_OS = #PB_OS_Linux
; 	gtk_window_set_icon_(WindowID(#Window), ImageID(0))
; CompilerEndIf

Re: Compiling an exe with multiple icons in it.

Posted: Mon Sep 11, 2023 5:31 pm
by fryquez
Purebasic installation comes with Pelles Resource Compiler.

create a .rc file like this:

Code: Select all

#define LANG_NEUTRAL 0
#define SUBLANG_NEUTRAL 0
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL

100 ICON "ICON100_1.ico"
101 ICON "ICON101_1.ico"
ABC ICON "ICONABC.ico"
and compile it to a res file.

Code: Select all

%PUREBASIC_HOME%\Compilers\porc.exe /R D:\WORK\Icons.rc.
The resulting Icons.res can be imported by Purebasic code.

Code: Select all

Import Icons.res
EndImport

Re: Compiling an exe with multiple icons in it.

Posted: Mon Sep 11, 2023 5:35 pm
by normeus
I have not used IcoFX. I use "greenfish icon editor" and you are able to save multiple icons of the same size and color depth:

(Freeware and Portable)
http://greenfishsoftware.org/gfie.php#apage


Norm.

Re: Compiling an exe with multiple icons in it.

Posted: Mon Sep 11, 2023 6:30 pm
by RASHAD
I think that mikejs is not asking to include as many icons in the exe file
But he is asking to compile an exe file with many icons that he can use exe properties to change the icon at any time
fryquez is the right way to do that except you don't need to compile the rc file
But just use PB compiler options to add the rc file directly
I hope I am right :)

Re: Compiling an exe with multiple icons in it.

Posted: Mon Sep 11, 2023 6:50 pm
by ChrisR
RASHAD wrote: Mon Sep 11, 2023 6:30 pm But just use PB compiler options to add the rc file directly
I hope I am right
Yes, I do it like this and it gives the same result as fryquez.

Create a .rc file (ex: Icons\Icon.rc) with for example:

Code: Select all

2 ICON "Icons/ICON2.ico"
100 ICON "Icons/ICON100.ico"
And in compiler options, resources tab, just add Icons\Icon.rc

Re: Compiling an exe with multiple icons in it.

Posted: Tue Sep 12, 2023 10:03 am
by mikejs
ChrisR wrote: Mon Sep 11, 2023 6:50 pm
RASHAD wrote: Mon Sep 11, 2023 6:30 pm But just use PB compiler options to add the rc file directly
I hope I am right
Yes, I do it like this and it gives the same result as fryquez.

Create a .rc file (ex: Icons\Icon.rc) with for example:

Code: Select all

2 ICON "Icons/ICON2.ico"
100 ICON "Icons/ICON100.ico"
And in compiler options, resources tab, just add Icons\Icon.rc
Thanks all, the above works perfectly.