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.

NOTE<br />

The <strong>C++</strong>Builder IDE Explored: Projects and Forms<br />

resource script is compiled <strong>in</strong>to an .RES file (the b<strong>in</strong>ary resource file), which then gets l<strong>in</strong>ked<br />

to the .EXE by the l<strong>in</strong>ker. At runtime the dialog box is displayed either modally or modelessly,<br />

depend<strong>in</strong>g on the dialog box’s <strong>in</strong>tended purpose. When the dialog box is executed, W<strong>in</strong>dows<br />

loads the dialog box resource from the executable file, builds the dialog box, and displays it.<br />

A modal dialog box is one that must be dismissed before the user can<br />

cont<strong>in</strong>ue us<strong>in</strong>g the application. The ma<strong>in</strong> w<strong>in</strong>dow of an application is<br />

disabled while this type of dialog box is open. Most dialog boxes are<br />

modal. The Compile Status dialog box <strong>in</strong> <strong>C++</strong>Builder is an example of<br />

a modal dialog box.<br />

A modeless dialog box is one that allows the user to cont<strong>in</strong>ue to work<br />

with the application while the dialog box is displayed. The F<strong>in</strong>d dialog<br />

box <strong>in</strong> some word-process<strong>in</strong>g programs is an example of a modeless<br />

dialog box.<br />

Now, with that background <strong>in</strong>formation on how dialog boxes are handled <strong>in</strong> a traditional<br />

W<strong>in</strong>dows program, let’s take a look at how <strong>C++</strong>Builder handles dialog boxes.<br />

Dialog Boxes <strong>in</strong> <strong>C++</strong>Builder<br />

In <strong>C++</strong>Builder, a dialog box is simply another form. You create a dialog box just like you do<br />

a ma<strong>in</strong> w<strong>in</strong>dow form or any other form. To prevent the dialog box from be<strong>in</strong>g sized, you can<br />

change the BorderStyle property to bsDialog or bsS<strong>in</strong>gle. If you use bsDialog, your dialog<br />

box will have only the close box on the title bar, which is traditional for dialog boxes. Other<br />

than that, you don’t have to do anyth<strong>in</strong>g special to get a form to behave like a dialog box. All<br />

<strong>C++</strong>Builder forms have tabb<strong>in</strong>g support built <strong>in</strong>. You can set the tab order by alter<strong>in</strong>g the<br />

TabOrder property of the <strong>in</strong>dividual controls on the dialog box.<br />

A <strong>C++</strong>Builder dialog box (any <strong>C++</strong>Builder form, actually) is modal or modeless, depend<strong>in</strong>g<br />

on how it is displayed. To execute a modal dialog box, you call the ShowModal() method of<br />

TForm. To create a modeless dialog box, you call the Show() method.<br />

Let’s add an About box to the multiple-forms project we created earlier. If you don’t have that<br />

project open, choose File | Open from the ma<strong>in</strong> menu or click the Open Project button on<br />

the toolbar and locate the file (you should have saved it with the project name Multiple).<br />

189<br />

6

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

Saved successfully!

Ooh no, something went wrong!