Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Introducing Printing

Surprisingly, no Printer control exists. Unlike most things in Visual Basic, sending output to the printer can be a tedious process. Printing requires that you send a fairly long list of instructions to your printer that describe exactly the way the output is to look. As easily as Visual Basic enables you to add and manage controls, one would have thought that the printing could be made easier.

Despite the tedium sometimes associated with printing, you will soon see that you can control every aspect of printing, including the font of individual characters that your application sends to the printer. The tedious control needed for printing provides pinpoint accuracy that lets you control all printing details.

The Windows print spooler, also known as the print queue or the printer subsystem, controls all printed output in Windows.

When your application sends output to the printer, Windows intercepts those printer commands. Rather than sending output directly to the printer attached to your computer, Visual Basic actually sends printed output to the Windows print spooler.

The print spooler determines how all printed output from all Windows programs eventually appears. Therefore, when your Visual Basic application attempts to send printed output directly to the printer, the Windows print spooler intercepts those commands and might change the output before the printer ever sees it.

The Windows print spooler knows how to communicate with any printer supported by Windows. There are hundreds of different kinds of printers now recognized by Windows, and most of these printers require specialized commands. If every program that you bought had to provide support for every kind of printer that you or your users might own, programs would require even more disk space than they already do. In addition, programs would cost more because each software developer would have to spend time writing the program to produce output onto every kind of printer available.

Rather than require that every software developer support all printers, the Windows print spooler requires that every software developer support only one kind of printed output: the kind required by the Windows print spooler. If the applications that you write need to produce printed output, Visual Basic produces that output in a form required by the Windows print spooler. Figure 16.1 shows that Visual Basic applications send output directly to the Windows print spooler. The Windows print spooler then converts that output into the individual commands needed by whatever printer is attached to the system.

16fig01.gif

Figure 16.1 Windows intercepts printer output.

Suppose that you had both a laser printer and a color ink-jet printer attached to your computer. Without the Windows print spooler, you would need to provide two sets of printer commands for every Visual Basic application you write. With the Windows print spooler, you need to provide only one generic set of printer output commands. Before running the application, you can use commands available in the Windows print spooler to select one of your two printers. When you run the program, Windows will convert the Visual Basic output into commands needed by whatever printer is selected.

Share ThisShare This

Informit Network