WINDOWS issue : How do you include icons into the exe ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

WINDOWS issue : How do you include icons into the exe ?

Post 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.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
AZJIO
Addict
Addict
Posts: 2193
Joined: Sun May 14, 2017 1:48 am

Re: WINDOWS issue : How do you include icons into the exe ?

Post 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.
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: WINDOWS issue : How do you include icons into the exe ?

Post 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
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: WINDOWS issue : How do you include icons into the exe ?

Post 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...
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: WINDOWS issue : How do you include icons into the exe ?

Post by Blue »

AZJIO wrote: Sun Mar 31, 2024 6:31 pm Open some file in the "Resource Hacker" program
[...]
You already have me stalled :oops: 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.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
AZJIO
Addict
Addict
Posts: 2193
Joined: Sun May 14, 2017 1:48 am

Re: WINDOWS issue : How do you include icons into the exe ?

Post 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
Axolotl
Addict
Addict
Posts: 853
Joined: Wed Dec 31, 2008 3:36 pm

Re: WINDOWS issue : How do you include icons into the exe ?

Post by Axolotl »

On the topic of resource files...
Perhaps this will help you get started.
Help with ressources files (.RC)
Ressources Files
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: WINDOWS issue : How do you include icons into the exe ?

Post 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.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: WINDOWS issue : How do you include icons into the exe ?

Post by Blue »

Axolotl wrote: Thu Apr 04, 2024 1:56 pm On the topic of resource files...
Perhaps this will help you get started.
Help with ressources files (.RC)
Ressources Files
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...
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
Axolotl
Addict
Addict
Posts: 853
Joined: Wed Dec 31, 2008 3:36 pm

Re: WINDOWS issue : How do you include icons into the exe ?

Post by Axolotl »

yes, what can i write.... I hadn't started the topic or wrote resources with two s's. :oops:
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.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
ChrisR
Addict
Addict
Posts: 1466
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: WINDOWS issue : How do you include icons into the exe ?

Post 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"
User avatar
Blue
Addict
Addict
Posts: 967
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: WINDOWS issue : How do you include icons into the exe ?

Post 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.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
AZJIO
Addict
Addict
Posts: 2193
Joined: Sun May 14, 2017 1:48 am

Re: WINDOWS issue : How do you include icons into the exe ?

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