Usually, print settings are defined in the form of a DEVMODE structure. For example, when you pass print settings to the CreateDC function, you are passing a pointer to a DEVMODE structure. Printer drivers usually store print settings as strings in the WIN.INI file in order to retain the settings between Windows sessions. Typically, your application does not create the DEVMODE structure itself; instead, it gets a complete structure from the printer driver and modifies it, as necessary. This method ensures that the structure is complete and correct.
The DEVMODE structure includes three types of information:
Information | Description |
Header information | The first five members in the DEVMODE structure make up the structure's header information. This information includes the model name (for example, “HP LaserJet Series II”), version information, and information about the size of the structure. You should always provide complete header information. |
Device-independent settings | Most of the members in the DEVMODE structure are device-independent settings, such as print orientation, paper size, and number of copies. Although the complete structure always includes all the device-independent settings, some printers do not support all the settings. For example, many printers can print on one side of the paper only; printer drivers for those printers would therefore ignore the DEVMODE structure's dmDuplex member, which specifies two-sided printing. |
Device-specific information | The optional dmDriverData member of DEVMODE contains device-specific information that is defined by each device driver. This information follows the DEVMODE structure in memory. Typically, an application would simply pass this information on without modifying it in any way. |
The best way to supply a complete DEVMODE structure when calling CreateDC is to first use the ExtDeviceMode function (included in printer drivers written for Windows versions 3.0 and later). This function tells the printer driver to create a DEVMODE structure by using its current print settings. Because the driver itself creates the DEVMODE structure and includes its device-specific information, your application treats the structure as complete and correct. The application can then pass the resulting DEVMODE structure when calling the CreateDC function.
Your application can modify the members of the DEVMODE structure created by ExtDeviceMode to create a customized device context. For example, an application could change the value of the dmOrientation member of DEVMODE from DMORIENT_PORTRAIT to DMORIENT_LANDSCAPE before passing the structure to the CreateDC function. An application should never customize the device context in this manner without first using the DeviceCapabilities and GetDeviceCaps functions to verify that the printer supports the changes.
For more information about the CreateDC function and the DEVMODE structure, see the Microsoft Windows Programmer's Reference, Volumes 2 and 3, respectively.