Just as you must obtain a handle to a device context before you paint on the video display, you must obtain a printer device context handle before printing. Once you have this handle (and have made the Escape calls necessary to announce your intention of creating a new document), you can use this printer device context handle the same way you use the video display device context handle—as the first parameter to the various GDI calls we've covered in the last four chapters.
In Chapter 11, you learned that you can get a handle to a device context for the entire video display by calling:
hdc = CreateDC ("DISPLAY", NULL, NULL, NULL) ;
You obtain a printer device context handle using this same function. However, for a printer device context, the first three parameters are not fixed. The general syntax of CreateDC is:
hdc = CreateDC (lpszDriverName, lpszDeviceName, lpszOutputPort,
lpInitializationData) ;
Although lpInitializationData is generally set to NULL, the first three parameters must be far pointers to character strings that tell Windows the name of the printer driver, the name of the printer device, and the output port to which the device is connected. Before you can set these three parameters, you must do a little fishing in the WIN.INI file.