++Builder provides an icon for
console-mode applications. It’s a nice icon (see
Figure A), but at first glance it looks too much like the
C++Builder icon. I can’t count the number of times
I’ve accidentally clicked on the wrong icon in the
Taskbar. Another problem is that if you have two or
more console-mode applications running at the same
time, they all use the same default icon.
| |
|
Figure A |
|
|
|
The default console-mode icon. |
|
| |
This
article provides a tutorial on customizing the icons
of console-mode applications. In addition, I talk
about creating transparent pixels in a customized
icon and creating 16×16-pixel icons using the
Borland Image Editor.
What to do
If you’ve done any significant
Windows or VCL programming using C++Builder, you
probably know about the “Load Icon” button on the
Applications panel on the project options screen.
Unfortunately, for console-mode applications, that
button is grayed out.
To
change the icon for a console-mode application,
first load its resource file into Image Editor, make
the changes and then save the modified resource
file. The new icon will be incorporated into the
executable after the resource file has been re-added
to the project or the Borland C++Builder IDE has
been restarted.
Where to start
Let's say your console-mode
application is called ConsoleApp. The first step is
to open the Project Manager view as shown in
Figure B.
| |
|
Figure B |
|
|
|
A typical console-mode
application contains a resource
file (.res), a Borland Project
File (.bpf) and, of course, the
C++ source file. |
|
| |
By default, the resource file is located in the same
directory as your console-mode application. For the
ConsoleApp project in
Figure B, the
resource file you need to open is called
ConsoleApp.RES.
Open the resource file using Borland’s Image Editor.
3-2-1… Launch the Image
Editor
There are two places where you
can find Image Editor:
1.
In the Borland C++Builder 6 program menu (via
“Start | Programs | Borland C++Builder 6 | Image
Editor”).
2.
In the C++Builder IDE; choose the “Tools”
menu and then choose “Image Editor”.
Open the resource file
In Image Editor, select “File |
Open” and then navigate to the
.RES
file for your console-mode application.
Open the icon
In a default console-mode
application’s resource file, the icon in the
resource file is called MAINICON. To open the
MAINICON icon, expand the Icon tree branch and
double-click on MAINICON(see
Figure C).
| |
|
Figure C |
|
|
|
The icon editing window contains
a pixel editor on the left side
and a full-size icon on the
right side. Transparent pixels
(the blue-green pixels) surround
the buildings. |
|
| |
The
double-click will open the icon editing window (Figure
D) in Image Editor. The icon editing
window has two parts: a pixel editor in the
left-hand panel and a full-size icon in the
right-hand panel. The default console-mode icon is a
32×32 pixel, 16-color icon.
| |
|
Figure D |
|
|
|
A default console-mode
application resource file
contains an icon called
MAINICON. |
|
| |
Opening your inner artist
The vertical toolbar on the
left side of Image Editor’s main window contains all
of your graphics-editing tools. Even though Image
Editor doesn’t have all of the features of a
high-priced graphics-editing application, you can
still make some pretty amazing icons easily and
quickly.
Icon basics
Every pixel in an icon can
either be colored or it can be transparent. Image
Editor displays transparent pixels using a dark teal
(blue-green) color. In the default Borland-supplied
icon, the pixels surrounding the buildings are all
transparent pixels.
Bulk erase
If you’re like me and you like
starting with a blank slate, the first thing you’ll
want to do is delete all of the colored pixels. As a
novice, I clicked on the eraser tool and started
erasing colored pixels. This was painfully slow
because it changed only one pixel at a time.
Next, I tried the Eye Dropper tool and clicked on
one of the transparent pixels. I then used the Fill
tool (it looks like a pouring paint bucket) to erase
large sections of the same color. This was better
than using the Eraser tool but it still left lots of
scattered pixels of different colors.
Finally, I tried the Brush tool. That was what I
needed. Because I had previously picked a
transparent pixel with the Eye Dropper tool, I was
able to use the Brush tool to quickly erase large
sections of the palette.
Later, I discovered I could left-click on the red
“S” near the color palette (Figure
E). This is the same as picking a
transparent pixel using the Eye Dropper tool and
it’s handy if the icon doesn’t have any transparent
pixels.
| |
|
Figure E |
|
|
|
Click on the red swooping “S” in
the color palette to create
transparent pixels in the pixel
editor. |
|
| |
Saving
When you're done customizing
your icon, you'll notice on the “File” menu
that the “Save” and “Save As” menu choices are
grayed-out. To save the icon, you first need to
click on the resource window (Figure
C); you'll then be able to save the icon
(and the resource file).
Seeing your icon
If you go back to C++Builder
and then
build and
execute your application, you'll be disappointed to
see the old icon. Even if you force the application
to
build,
you'll still see the old icon! The linker apparently
caches the
.RES file. There are two ways to force a
changed resource file to be incorporated into an
executable:
1.
Remove the resource file from the project and
then add it back again.
2.
Close the Borland IDE and launch it again.
Creating 16x16-pixel icons
The Windows Taskbar and the
application’s title bar typically use 16×16-pixel
icons. If the only icon available is a 32×32-pixel
icon, Windows will shrink its size to 16×16 pixels.
Sometimes the 32×32-pixel icon doesn't render well
when it's shrunk to 16×16. Likewise, if the resource
file defines only a 16x16-pixel icon, it might have
a “jagged” (aliased) look when it’s rendered as a
32×32-pixel icon. It’s therefore a good idea to
include both 16×16-pixel and 32×32-pixel icons in
your resource file.
On
the icon editing window in Image Editor (shown in
Figure D),
click on the “New” button to add a 16×16-pixel icon
to the resource. The Icon Properties window will
appear.
Choose the 16×16 (small icon) size and then click
“OK.” A new, empty 16×16-pixel icon is displayed in
the icon editing window. You can easily switch back
and forth between the icons by clicking on the combo
box in the icon editing window (see
Figure D).
Installing a resource file (.RES)
that contains a 16×16-pixel icon is the same as
installing it with a 32×32-pixel icon:
1.
Save the resource file.
2.
Remove the resource file from the project.
3.
Add it back into the project.
4.
Build or make the application.
Making it easier
After you’ve erased all of the
pixels from an icon, save the resource file in an
easy-to-find location (I chose the
icons/ directory in the C++Builder root directory).
The next time you need to customize an icon, launch
Image Editor and open the empty resource file that
you previously saved. You can safely overwrite the
.RES
file in your project but you’ll still need to use
the remove/add trick to make the linker realize that
the .RES
file has been changed.
Conclusion
Custom icons help to
differentiate your console-mode applications at
runtime and when they are picked from Windows
Explorer. Creating a custom icon is easy. When
you’re ready to distribute your executable, the
Borland C++ compiler incorporates the icon resource
into the executable so you don’t need to provide any
other files.

Contact Curtis at
curtis@decompile.com.