Printer Device Contexts Overview
Just as an application requires a display DC before it can begin drawing in the client area of a window, it needs a special printer DC before it can begin sending output to a printer. A printer DC is similar to a display DC in that it is an internal data structure that defines a set of graphic objects and their associated attributes and specifies the graphic modes that affect output. The graphic objects include a pen (for line drawing), a brush (for painting and filling), and a font (for text output).
Unlike a display DC, printer DCs are not owned by the window management component, and they cannot be obtained by calling the GetDC function. Instead, an application must call the CreateDC or PrintDlg function. When an application calls CreateDC, it must supply a driver and port name. This data is stored in one of the operating system initialization (.INI) files. It can be retrieved by calling the EnumPrinters function.
When an application calls PrintDlg and specifies the PD_RETURNDC value in the Flags member of the PRINTDLG structure, Windows automatically returns a handle identifying the user's selected printer DC. For an example that demonstrates this task, see Using a Print Dialog Box and Retrieving a Printer Device Context.