How to Create Device-Independent Printing Code

Last reviewed: January 5, 1995
Article ID: Q76260
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

Windows provides a device-independent platform for application developers. Device independence applies to printing as well. To write code to work with any printer driver, applications must not rely on any special feature in a printer driver. Instead, applications should direct all requests through the Windows Graphical Device Interface (GDI).

MORE INFORMATION

There are two major classes of printers: raster printers and PostScript printers. This article is directed towards application support for raster printers.

With the exception of the standard printer escapes, applications should not rely on any printer escape to be supported in a particular printer driver. Note that the printer escapes are supported in Windows 3.1, but it is recommended that you use the new equivalent functions, instead of the escapes.

The standard escapes/functions are: STARTDOC/StartDoc(), ENDDOC/EndDoc(), NEXTBAND, NEWFRAME, SETABORTPROC/SetAbortProc(), and ABORTDOC/AbortDoc(). The remaining escapes are optional for printer drivers. Applications should use the QUERYESCSUPPORT escape to test for the support of optional escapes. Applications should not depend on private knowledge of how a particular driver works.

For example, the DRAWPATTERNRECT escape is available on certain devices. The following code fragment determines if the DRAWPATTERNRECT escape is supported on the installed device. If not, an alternative function, PatBlt(), is used to create the output.

  short i;

  i = DRAWPATTERNRECT;

  if (Escape(hPr, QUERYESCSUPPORT, sizeof(i), (LPSTR)&i, NULL))
      Escape(hPr, DRAWPATTERNRECT, sizeof(lpPatRect),
               (LPSTR)lpPatRect, NULL);
  else
      PatBlt(hPr, .....);

Of the remaining escapes, the following are used frequently: GETPHYSPAGESIZE, GETPRINTINGOFFSET, PASSTHROUGH, and DRAWPATTERNRECT. An application should minimize the number of escapes that it uses.

Another area of device independence applies to ExtDeviceMode(). Applications should not allow the user to change printer settings globally. If the user wants to change the printer settings for all applications, the Control Panel utility should be used. It is more appropriate for printer settings to be associated with an application, a document, or a particular set of pages in a document. For more information please see the Knowledge Base article

   "Using ExtDeviceMode() to Modify Printer Settings"


Additional reference words: 3.00 3.10
KBCategory: kbprg
KBSubcategory: GdiPrn


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 5, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.