User forums > Using Code::Blocks
How to add icon and version information to .exe?
Sindarin:
I am coding a Windows GUI Application in CB. I can compile my program perfectly. Problem is that I need to add a custom icon and version information in it.
As CodeBlocks has not a resource editor I had to do it myself. But it doesn't work. I checked numerous threads and the Code Blocks FAQ, but nothing solved my problems.
The files in my project root are main.cpp, resource.rc, icon.ico, theprogram.cbp, theprogram.layout
My program in main.cpp
--- Quote ---#include <windows.h>
#include "resource.rc" //I indeed include resource.rc
...winmain, winproc etc.
--- End quote ---
resource.rc
--- Code: ---#include <windows.h> // include for version info constants
//ICON
A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "icon.ico"
//VERSIONINFO
1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILETYPE VFT_APP
{
BLOCK "StringFileInfo"
{
BLOCK "080904E4"
{
VALUE "CompanyName", ""
VALUE "FileVersion", ""
VALUE "FileDescription", "testing the description"
VALUE "InternalName", ""
VALUE "LegalCopyright", ""
VALUE "LegalTrademarks", ""
VALUE "OriginalFilename", ""
VALUE "ProductName", ""
VALUE "ProductVersion", ""
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0809, 1252
}
}
--- End code ---
The Compiler stops in
C:\CPP Projects\theprogram\resource.rc|7|error: `A' does not name a type|
||=== Build finished: 1 errors, 0 warnings ===|
Any help? Thanks in advance.
MortenMacFly:
--- Quote from: Sindarin on September 04, 2009, 05:42:21 pm ---
--- Code: ---A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "icon.ico"
--- End code ---
--- End quote ---
I don't think "A" is a valid keyword in a resource file. That's exactly what the resource compiler tells you. Icons are embedded completely different.
Sindarin:
--- Quote ---I don't think "A" is a valid keyword in a resource file. That's exactly what the resource compiler tells you. Icons are embedded completely different.
--- End quote ---
I got the syntax from a resource file DevC++ created. I need to copy paste over the code to DevC++ to get my icon and version information correctly.
Anyone can provide a working example or resource creating and integration?
MortenMacFly:
--- Quote from: Sindarin on September 05, 2009, 09:32:51 pm ---Anyone can provide a working example or resource creating and integration?
--- End quote ---
Why don't you read yourself into resouce files if you want to use them? All information required is available, including examples from MSDN.
In the end: You should understand what you develop, right? What worth would be your software if you don't?
Sindarin:
Yes, but I could use some extra help, that's why I posted in this forum?
Nevertheless I found a solution, I'll leave it here in case someone else needs it.
In your main.cpp file add the line:
#include <winver.h>
Place your icon "myiconfilename.ico" file inside the project folder.
Create a new file in the project folder called resources.rc, and write into it
--- Code: ---#define VOS_NT_WINDOWS32 0x00040004L
#define VFT_APP 0x00000001L
//this will set your .exe icon
A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "myiconfilename.ico"
//include version information in .exe, modify these values to match your needs
1 VERSIONINFO
FILEVERSION 0,1,1,1
PRODUCTVERSION 0,1,1,1
FILETYPE VFT_APP
{
BLOCK "StringFileInfo"
{
BLOCK "040904E4"
{
VALUE "CompanyName", "write version info here"
VALUE "FileVersion", "write version info here"
VALUE "FileDescription", "write version info here"
VALUE "InternalName", "write version info here"
VALUE "LegalCopyright", "write version info here"
VALUE "LegalTrademarks", "write version info here"
VALUE "OriginalFilename", "write version info here"
VALUE "ProductName", "write version info here"
VALUE "ProductVersion", "write version info here"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0409, 1252 //language codes
}
}
--- End code ---
finally ADD the resources.rc and the icon in the CodeBlocks IDE by right clicking on the Management and selecting "Add Files..."
You're done!
Also if you want your controls (buttons, checkboxes etc.) to support modern Windows XP and Vista styles,
you must write a new file called "xp.manifest" and place it in the project folder as well, the file will contain an xml structure:
--- Code: ---<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
name="Exe.Apps.Project"
processorArchitecture="x86"
version="1.0.0.0"
type="win32"/>
<description>Project</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="x86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
--- End code ---
Then update your resources.rc file with the line:
--- Code: ---1 24 "xp.manifest"
--- End code ---
There you go. :)
I also suggest you update your F.A.Q. since it didn't provide enough info to solve my problem, let alone for other more inexperienced users.
Navigation
[0] Message Index
[#] Next page
Go to full version