12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

342 Day 9<br />

■ Dialog boxes<br />

■ Icons<br />

■ Menus<br />

■ Data tables<br />

■ Str<strong>in</strong>g tables<br />

■ Version <strong>in</strong>formation<br />

■ User-def<strong>in</strong>ed specialty resources (sound files and AVI files, for example)<br />

Resources are generally conta<strong>in</strong>ed <strong>in</strong> a resource script file (a text file with an .rc extension),<br />

which is compiled by a resource compiler and then bound to the application’s .exe file dur<strong>in</strong>g<br />

the l<strong>in</strong>k phase.<br />

Resources are usually thought of as be<strong>in</strong>g bound to the executable file. Some resources, such<br />

as bitmaps, str<strong>in</strong>g tables, and wave files, can be placed <strong>in</strong> external files (.bmp, .txt, and .wav),<br />

or they can be bound to the .exe and conta<strong>in</strong>ed with<strong>in</strong> the application file. You can opt to<br />

do it either way. Plac<strong>in</strong>g resources <strong>in</strong> the .exe file has two ma<strong>in</strong> advantages:<br />

■ The resources can be accessed more quickly because it takes less time to locate a<br />

resource <strong>in</strong> the executable file than it does to load it from a disk file.<br />

■ The program file and resources can be conta<strong>in</strong>ed <strong>in</strong> a s<strong>in</strong>gle unit (the .exe file)<br />

without the need for a lot of support<strong>in</strong>g files.<br />

The downside to this approach is that your .exe will be slightly larger. The program file won’t<br />

be any larger than the comb<strong>in</strong>ed external resource files plus the executable, but the extra size<br />

could result <strong>in</strong> slightly longer load times for the program.<br />

Your exact needs will determ<strong>in</strong>e whether you decide to keep your resources <strong>in</strong> external files<br />

or have your resources bound to the .exe. The important th<strong>in</strong>g to remember is that you can<br />

do it either way (or even both ways <strong>in</strong> the same program).<br />

A traditional W<strong>in</strong>dows program will almost always conta<strong>in</strong> at least one dialog box and an<br />

icon. A <strong>C++</strong>Builder application, however, is a little different. First, there are no true dialog<br />

boxes <strong>in</strong> a <strong>C++</strong>Builder application, so there are no dialog box resources per se<br />

(<strong>C++</strong>Builder forms are stored as resources, but they are RCDATA resources and not dialog box<br />

resources). A <strong>C++</strong>Builder application does have a traditional icon resource, though. <strong>C++</strong>Builder<br />

takes care of creat<strong>in</strong>g the resource file for the icon for you when you create the application.<br />

Similarly, when you choose bitmaps for speed buttons, Image components, or BitBtn<br />

components, <strong>C++</strong>Builder <strong>in</strong>cludes the bitmap file you chose as part of the form’s resource.<br />

The form and all its resources are then bound to the program file when the application is built.<br />

It’s all more or less handled for you automatically.<br />

There are times, however, when you will want to implement resources aside from the normal<br />

<strong>C++</strong>Builder processes. For <strong>in</strong>stance, if you want to do animation, you will have to have a series

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!