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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

130: //<br />

131: Application->ProcessMessages();<br />

132: //<br />

133: // take a short nap so the animation doesn’t go too fast<br />

134: //<br />

135: Sleep(20);<br />

136: }<br />

List<strong>in</strong>g 9.4. JJRes.rc.<br />

1: #def<strong>in</strong>e IDS_UP 101<br />

2: #def<strong>in</strong>e IDS_DOWN 102<br />

3:<br />

4: STRINGTABLE<br />

5: {<br />

6: IDS_UP, “Up”<br />

7: IDS_DOWN, “Down”<br />

8: }<br />

9:<br />

10: ID_WAVEUP WAVE “up.wav”<br />

11: ID_WAVEDOWN WAVE “down.wav”<br />

12:<br />

13: ID_BITMAP1 BITMAP LOADONCALL MOVEABLE DISCARDABLE IMPURE<br />

<strong>14</strong>: {<br />

15: ’42 4D 76 02 00 00 00 00 00 00 76 00 00 00 28 00'<br />

16: ’00 00 20 00 00 00 20 00 00 00 01 00 04 00 00 00'<br />

17: //<br />

18: // rema<strong>in</strong>der of bitmap resources follow<br />

Notice l<strong>in</strong>es 23 and 24 <strong>in</strong> the header for the ma<strong>in</strong> form class <strong>in</strong> List<strong>in</strong>g 9.2. L<strong>in</strong>e 23<br />

ANALYSIS<br />

declares a bool data member that is used to determ<strong>in</strong>e when to stop the animation.<br />

The class member function declared on l<strong>in</strong>e 24 is used to display the bitmap <strong>in</strong> the Image<br />

component.<br />

In List<strong>in</strong>g 9.3 you will notice that two W<strong>in</strong>dows API functions are used to load the str<strong>in</strong>g and<br />

wave file resources. On l<strong>in</strong>e 78, the LoadStr<strong>in</strong>g() function loads a str<strong>in</strong>g resource <strong>in</strong>to a text<br />

buffer based on the numerical identifier of the str<strong>in</strong>g (see List<strong>in</strong>g 9.4 to see how the str<strong>in</strong>g<br />

resources are created). The str<strong>in</strong>g is then assigned to the Caption property of the label<br />

component on the form. On l<strong>in</strong>e 83, the PlaySound() function is used to play a wave file<br />

conta<strong>in</strong>ed as a resource. The SND_ASYNC flag used with the PlaySound() function tells<br />

W<strong>in</strong>dows to play the sound and immediately return control to the program. This allows the<br />

animation to cont<strong>in</strong>ue while the sound is be<strong>in</strong>g played. The SND_RESOURCE flag tells W<strong>in</strong>dows<br />

that the sound is conta<strong>in</strong>ed as a resource and not as a file on disk. Both the LoadStr<strong>in</strong>g() and<br />

PlaySound() functions use the HInstance global variable to tell W<strong>in</strong>dows to look <strong>in</strong> the<br />

executable file for the resources.<br />

347<br />

9

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

Saved successfully!

Ooh no, something went wrong!