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.

Creat<strong>in</strong>g Applications <strong>in</strong> <strong>C++</strong>Builder<br />

of bitmaps that can be loaded as resources for the fastest possible execution speed. In this k<strong>in</strong>d<br />

of situation, you are go<strong>in</strong>g to need to know how to b<strong>in</strong>d the resources to your <strong>C++</strong>Builder<br />

program file.<br />

The act of b<strong>in</strong>d<strong>in</strong>g the resource file to the executable is trivial, actually. It’s much more<br />

difficult to actually create the resources. Creat<strong>in</strong>g basic resources such as bitmaps, icons, and<br />

cursors is not difficult with a good resource editor, but creat<strong>in</strong>g professional-quality 3D<br />

bitmaps and icons is an art. How many times have you seen a pretty decent program with<br />

really awful bitmap buttons? I’ve seen plenty. (Oops, looks like I’m gett<strong>in</strong>g off track here.)<br />

You can create bitmaps, icons, and cursors with the <strong>C++</strong>Builder Image Editor. If you are<br />

go<strong>in</strong>g to create str<strong>in</strong>g resources, user data resources, wave file resources, or other specialty<br />

resources, you will probably need a third-party resource editor.<br />

NOTE<br />

If you have <strong>Borland</strong> <strong>C++</strong>, you can use the Resource Workshop from<br />

that package to edit specialty resources. After creat<strong>in</strong>g the resources,<br />

you will have an .rc file that you can either add to your <strong>C++</strong>Builder<br />

project directly or compile <strong>in</strong>to a .res file us<strong>in</strong>g the <strong>Borland</strong> Resource<br />

Compiler (BRCC32.EXE). The <strong>Borland</strong> Resource Compiler comes with<br />

both <strong>Borland</strong> <strong>C++</strong> and <strong>C++</strong>Builder. Technically, you could create the<br />

.rc file with any text editor and compile it with the Resource Compiler,<br />

but <strong>in</strong> reality it is much easier to use a resource editor.<br />

You can add either a .res file or an .rc file to your project via the Project Manager. To add<br />

a resource file to a project us<strong>in</strong>g the Project Manager, you first choose View | Project Manger<br />

from the ma<strong>in</strong> menu. When the Project Manager dialog box is displayed, click the Add To<br />

Project button. When the File Open dialog box appears, select the resource file you want to<br />

add to the project and click OK. The resource file shows up <strong>in</strong> the Project Manager with the<br />

rest of the application’s files. I’ll discuss the Project Manager <strong>in</strong> more detail tomorrow.<br />

List<strong>in</strong>gs 9.2 and 9.3 conta<strong>in</strong> the header and ma<strong>in</strong> form unit for a program called Jump<strong>in</strong>g<br />

Jack. This program shows a simple animation with sound effects. The ma<strong>in</strong> form conta<strong>in</strong>s<br />

just two buttons, an Image component, and a Label component. The Jump<strong>in</strong>g Jack program<br />

illustrates several aspects of us<strong>in</strong>g resources <strong>in</strong> a <strong>C++</strong>Builder application. (The program can<br />

be found at http://www.mcp.com/sams/codecenter.html.) Specifically, it shows how to load<br />

a bitmap stored as a resource, how to load and display a str<strong>in</strong>g resource, and how to play wave<br />

audio conta<strong>in</strong>ed as a resource. List<strong>in</strong>g 9.4 is a partial list<strong>in</strong>g of the resource file that is used<br />

by the Jump<strong>in</strong>g Jack program. Exam<strong>in</strong>e the list<strong>in</strong>gs, and then we’ll discuss what the program<br />

does.<br />

343<br />

9

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

Saved successfully!

Ooh no, something went wrong!