Chapter 13

Printing and Print Previewing

For beginning programmers, learning to print is one of the single most daunting aspects of Microsoft Windows programming. Printing has never been easy in Windows because the same GDI that provides a device-independent interface to every kind of printer imaginable makes you jump through hoops to print a simple document. The GDI also gives you such precise control over the output that users expect a lot from Windows applications that produce printed documents. The good news is that the same GDI functions you use to draw on the screen can be used to draw on a sheet of paper. The bad news is that printing entails lots of extra details, from paginating the output to giving the user the means to terminate an unfinished print job. And if you really want your product to be competitive, you should probably support print previewing so that the user can see exactly what the printed output will look like before he or she sends the first page to the printer.

In Chapters 9, 10, 11, and 12, you saw how the document/view architecture simplifies the development of single document interface (SDI) and multiple document interface (MDI) applications by letting MFC take over key aspects of a program's operation. In this chapter, you'll learn how the same document/view architecture simplifies printing and print previewing. Even MFC-style printing isn't something to be taken lightly, but thanks to the support the framework offers, the tedium of writing and testing code that renders documents on printers and other hardcopy devices is sharply reduced. And once you've given an application the ability to print, print previewing comes almost for free.