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.

132 Day 5<br />

Frameworks 101<br />

“In the beg<strong>in</strong>n<strong>in</strong>g there was C….” If you recall, I started my discussion of the <strong>C++</strong><br />

programm<strong>in</strong>g language with that statement. The same is true of W<strong>in</strong>dows programm<strong>in</strong>g—<br />

<strong>in</strong> the beg<strong>in</strong>n<strong>in</strong>g, the vast majority of W<strong>in</strong>dows programs were written <strong>in</strong> C. In fact, the<br />

W<strong>in</strong>dows Application Programm<strong>in</strong>g Interface (API) is just a huge collection of C functions—hundreds<br />

of them. There are still undoubtedly thousands of programmers out there<br />

writ<strong>in</strong>g W<strong>in</strong>dows programs <strong>in</strong> C.<br />

Somewhere along the l<strong>in</strong>e, some folks at <strong>Borland</strong> decided, “There has got to be an easier way!”<br />

(Actually, the framework revolution may have started on several different fronts at once, but<br />

<strong>Borland</strong> was certa<strong>in</strong>ly a leader <strong>in</strong> the field.) It was apparent that W<strong>in</strong>dows programm<strong>in</strong>g was<br />

very well suited to the <strong>C++</strong> language, and vice versa. By creat<strong>in</strong>g classes that encapsulate<br />

common W<strong>in</strong>dows programm<strong>in</strong>g tasks, a programmer could be much more productive.<br />

Once a class was created to encapsulate the various duties of a w<strong>in</strong>dow, for <strong>in</strong>stance, that class<br />

could be used over and over aga<strong>in</strong>. The framework revolution began.<br />

But I haven’t actually told you what a framework is yet.<br />

A framework is a collection of classes that simplifies programm<strong>in</strong>g <strong>in</strong> W<strong>in</strong>dows by<br />

encapsulat<strong>in</strong>g often-used programm<strong>in</strong>g techniques. Frameworks are also called class<br />

libraries.<br />

Popular frameworks have classes that encapsulate w<strong>in</strong>dows, edit controls, list boxes, graphics<br />

operations, bitmaps, scrollbars, dialog boxes, and on and on.<br />

NEW TERM<br />

So What’s the Big Deal?<br />

That’s a good question. The bottom l<strong>in</strong>e is that frameworks make W<strong>in</strong>dows programm<strong>in</strong>g<br />

much easier than it would be <strong>in</strong> straight C. Let me give you an example. List<strong>in</strong>g 5.1 conta<strong>in</strong>s<br />

a portion of a W<strong>in</strong>dows program written <strong>in</strong> C. This section of code loads a bitmap file from<br />

disk and displays the bitmap <strong>in</strong> the center of the screen. None of this will make sense to you<br />

right now, but that’s not the po<strong>in</strong>t.<br />

List<strong>in</strong>g 5.1. C code to load and display a bitmap.<br />

1: HPALETTE hPal;<br />

2: BITMAPFILEHEADER bfh;<br />

3: BITMAPINFOHEADER bih;<br />

4: LPBITMAPINFO lpbi = 0;<br />

5: HFILE hFile;<br />

6: DWORD nClrUsed, nSize;<br />

7: HDC hDC;

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

Saved successfully!

Ooh no, something went wrong!