Page 1 of 1
WINDOWS issue : How do you include icons into the exe ?
Posted: Sun Mar 31, 2024 5:39 pm
by Blue
I know how to include data in a compiled program using IncludeBinary() and CatchImage()
but that does not make the icon visible so that you can assign specific icons to specific filetypes.
I think that can only be done using a resource script.
I would be grateful if someone could provide a complete working (but simple) example to srudy and learn from.
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Sun Mar 31, 2024 6:31 pm
by AZJIO
Open some file in the "
Resource Hacker" program and select "Save group to *rc file" from the menu. You will have icons and an rc file. Next, you disable the icon in the compiler settings, and add an rc file in the resources tab. Compile the program and view the icons using the Resource Hacker program.
There may be an error in the section "LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL", so delete this line and leave the following text:
Code: Select all
1 ICON "ICON1_1.ico"
2 ICON "ICON1_2.ico"
where 1 and 2 are the icon number/name, and ICON1_1.ico is the file name.
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Sun Mar 31, 2024 6:52 pm
by Bisonte
Blue wrote: Sun Mar 31, 2024 5:39 pm
I know how to include data in a compiled program using
IncludeBinary() and
CatchImage()
but that does not make the icon visible so that you can assign specific icons to specific filetypes.
I think that can only be done using a
resource script.
I would be grateful if someone could provide a complete working (but simple) example to srudy and learn from.
You hae to assign the icon like this ... :
https://www.purebasic.fr/english/viewtopic.php?t=34543
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Thu Apr 04, 2024 3:21 am
by Blue
Thank you AZJIO and Bisonte for taking the time to reply.
(I was not ignoring you or this topic, i was simply under the weather for the past days.)
I'll study your suggestions and see if I finally understand how to prepare resource files and get them to work in PB.
I still wish there was some kind of detailed tutorial on this important Windows topic...
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Thu Apr 04, 2024 3:38 am
by Blue
You already have me stalled

with your first 3 words :
Open some file ???
Could you be more vague ?
What type of file should that be ?
A text file ? An icon file ? What should the file be or contain ?
Thanks for reminding me of the existence of Resource Hacker.
I had forgotten about the very existence of that excellent and most useful helper program.
I refreshed it.
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Thu Apr 04, 2024 3:48 am
by AZJIO
Blue wrote: Thu Apr 04, 2024 3:38 am
A text file ? An icon file ? What should the file be or contain ?
exe,dll,ocx,res,cpl,ax,scr,apl
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Thu Apr 04, 2024 1:56 pm
by Axolotl
On the topic of resource files...
Perhaps this will help you get started.
Help with ressources files (.RC)
Ressources Files
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Thu Apr 04, 2024 3:27 pm
by Blue
AZJIO wrote: Thu Apr 04, 2024 3:48 am
[...]
exe,dll,ocx,res,cpl,ax,scr,apl
Ah ! Now I understand. Thank you
AZJIO for being specific and a lot clearer.
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Thu Apr 04, 2024 3:34 pm
by Blue
Excellent link,
Axolotl. Much appreciated.
But pay attention to this all important detail : searching the forum for
resource will
NOT find
ressource...
CORRECTION : Sorry
Axolotl. After reading the post you referenced, I realize that you're not the one that used
ressource for
resource. Apologies...
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Thu Apr 04, 2024 3:43 pm
by Axolotl
yes, what can i write.... I hadn't started the topic or wrote resources with two s's.
that's why I - personally - always try different spellings
I'm certainly pleased if I was able to help.
EDIT: written before your correction and apology not needed.
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Thu Apr 04, 2024 4:39 pm
by ChrisR
Blue wrote: Sun Mar 31, 2024 5:39 pm
That does not make the icon visible so that you can assign specific icons to specific filetypes.
To include icons in your exe icon resource,
create a .rc file (ex: Icons\Icon.rc) with notepad and with for example:
Code: Select all
1 ICON "Icons/ICON1.ico"
100 ICON "Icons/ICON100.ico"
Then in compiler options, resources tab, just add Icons\Icon.rc
For the file association, it can be done with cmd:
Code: Select all
; Needs Compile Request Administrator mode
RunProgram("cmd.exe", "/c Assoc .icef=IceForm&&Ftype IceForm="+#DQUOTE$+"%ProgramFiles%\PureBasic\Tools\IceDesign.exe"+#DQUOTE$+" "+#DQUOTE$+"%1"+#DQUOTE$, "", #PB_Program_Wait | #PB_Program_Hide)
Then, you can insert the icon with the appropriate index in the registry
HKCR\IceForm\DefaultIcon, Default REG_SZ = "C:\Program Files\PureBasic\Tools\IceDesign.exe,1"
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Thu Apr 04, 2024 6:02 pm
by Blue
Thanks, ChrisR for the best — and most complete — explanation I’ve had so far.
The fog is dissipating.
As we say where I live, I catch quickly, as long as you explain lengthily.
Re: WINDOWS issue : How do you include icons into the exe ?
Posted: Thu Apr 04, 2024 11:31 pm
by AZJIO
If your task is to create a library of icons for file extensions, then another option will be easier.
1. The new version of "Resource Hacker" has a menu item "Create an empty script" that allows you to save the DLL. Specify extension when saving.
2. The old version of the program allows you to add resources using a script
Code: Select all
[FILENAMES]
Exe=Recovery_associative_icons.dll
SaveAs=Recovery_associative_icons.dll
Log=Recovery_associative_icons.log
[COMMANDS]
-addoverwrite Recovery_associative_icons.ico, IconGroup,99,
-addoverwrite 1.ico, IconGroup,201,
-addoverwrite 2.ico, IconGroup,202,
-addoverwrite 3.ico, IconGroup,203,
CMD file for launching DLL build script
Code: Select all
REM @echo off
color 3b
echo.
"%~dp0ResHacker.exe" -script Recovery_associative_icons_modify_script.txt
pause
The new version can do it too, but it needs to be studied, the behavior has changed and I couldn’t do some things, so I suggest doing it using the old 3.4.0.79
3. You can look at my program
Recovery_associative_icons, which in the source code shows how to assemble icons in dll. I wrote it on WinXP, but I also tried it on Win10.
Also have a look at my
ContMenuFiles program