Microsoft KB Archive/10471
INF: Controlling the Windows Printer Settings ID Number: Q10471
Summary: Some Windows version 3.0 printer drivers implement a convention for controlling print settings on a job-by-job basis, without requiring the printer to post the printer driver’s setup dialog box. An application can save properties, such as orientation and paper size, as part of a document’s page settings.
Some version 3.0 printer drivers, such as HPPCL and PSCRIPT, implement two new functions, ExtDeviceMode() and DeviceCapabilities(), and support a device-independent format for their DEVMODE structures.
The DEVMODE structure is the format for the environment used by a printer driver. Whenever a device context (DC) is created specifying a printer driver, or the printer driver puts up its dialog box, that driver associates a data structure, the DEVMODE, with the port. This DEVMODE can be retrieved using GetEnvironment(). The DEVMODE structure reflects the settings in the printer dialog box and in WIN.INI.
Commonly used fields in DEVMODE store the orientation, page size, bin, and so on.
The fourth parameter of CreateDC() is a pointer to a DEVMODE structure. Therefore, an application may save a DEVMODE structure and pass it to CreateDC() later. When a DEVMODE structure is passed to CreateDC(), it will override the default printer settings for the device.
A DEVMODE structure can be directly obtained or manipulated using the ExtDeviceMode() driver function. This function also allows an application to put up the driver’s dialog box with application supplied settings.
DeviceCapabilities() provides information about what settings the printer supports.
By using ExtDeviceMode(), an application can maintain its own print settings, even on a document-by-document basis. Furthermore, because part of DEVMODE is device independent, the application can directly manipulate common settings such as orientation.
This topic is discussed in detail in Chapter 17 of the “Microsoft Windows Software Development Kit Guide to Programming.”