Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Stingray Foundation Library User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

9.4 Printer Configurations

The Windows API defines two structures for identifying and configuring printers, or more specifically, printer device drivers. The DEVNAMES structure identifies a particular printer device driver, and the information it contains can be used to create a device context for the specified printer. The DEVMODE structure is used in conjunction with the DEVNAMES structure in order to create a device context for the specified printer. The DEVNAMES structure contains information such as page orientation, page size, and margins that is used to configure the printer device context. Anyone who has used the DEVNAMES and DEVMODE structures and the Windows printing API directly will tell you how difficult and time consuming it can be.

The CPrinterConfig class encapsulates the DEVNAMES and DEVMODE structures and hides the messy details of the Windows API functions that use these structures. The CPrinterConfig class takes care of allocating and manipulating the DEVNAMES and DEVMODE structures, which is particularly nice since these are variable length structures whose size is determined by the printer device driver.

CPrinterConfig provides methods such as GetOrientation(), SetOrientation(), GetPaperSize(), SetPaperSize(), GetNumCopies(), and SetNumCopies() for accessing the data in these structures. The PRINTDLG and PAGESETUPDLG structures can be used to store and retrieve the printer configuration using the following methods: LoadPrintDlg(), StorePrintDlg(), LoadPageSetupDlg(), and StorePageSetupDlg().

This makes it incredibly simple to use the CPrinterConfig class in conjunction with the common Windows print dialogs. The default system printer can be easily loaded into the printer configuration using the SetDefaultPrinter() method. The CPrinterConfig class also provides direct access to the DEVNAMES and DEVMODE structures through the GetDevNames() and GetDevMode() methods, so that you can still get to them if you need to.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.