DOCERR: Bad Printing Code Example in Guide to ProgrammingLast reviewed: July 23, 1997Article ID: Q99109 |
3.10
WINDOWS
kbprg kbdocerr
SUMMARYSection 12.4 of the Microsoft Windows version 3.1 Software Development Kit (SDK) "Guide to Programming" details code that uses BitBlt() to transfer a bitmap to a printer device context (DC). Unfortunately, the code sample uses LoadBitmap(), which returns a device-dependent bitmap (DDB) that is compatible with the display DC, not the printer DC. This code causes erroneous results on some printers.
MORE INFORMATIONBecause the sample code does not implement banding [it is using StartPage() and EndPage()--the Windows 3.1 replacement functions for the NEWFRAME Escape], this code should work fine on banding devices such as Hewlett-Packard (HP) LaserJet or dot-matrix printers. When an application does not perform banding and is printing to a banding device, GDI uses a disk-based metafile to perform banding on the application's behalf. As the application makes GDI calls, the calls are recorded into the metafile rather than being sent directly to the printer. When the application calls EndPage (or NEWFRAME), GDI enters an internal banding loop. GDI performs NEXTBAND escapes as needed and uses PlayMetaFile() to play the entire metafile into every band. During the playback of the metafile, GDI converts the DDB to a device-independent bitmap (DIB) and prints the DIB by calling SetDIBitsToDevice(). Because of the DDB-to-DIB conversion, the code works correctly on banding devices. When printing to a nonbanding device such as a PostScript printer, there is no intermediary metafile, and thus there is no DDB-to-DIB conversion taking place. This code leads to either a general protection (GP) fault, garbage output, or no output (depending on how gracefully the printer driver handles the error of being given a bitmap compatible with the display when it thinks it has a bitmap in its own internal format). If the code is altered slightly to implement banding (the NEXTBAND Escape), the same problem will occur. The sample code should be modified in two very important ways:
DIBVIEW can be found in the SAMPLES directory of the Windows SDK version 3.1, and versions 7.0 and 8.0 of the Microsoft C/C++ Optimizing Compiler. For Microsoft OnLine customers, DIBVIEW is available in the Microsoft Software Library as 5X13.ZIP and can be found by searching on the word DIBVIEW.
|
Additional reference words: 3.10 banding gp-fault gpf docerr
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |