Your application must also declare new variables to support printing. Add the following declarations to the beginning of your source file:
HDC hdcPrinter; /* handle of printer device context */
int LineSpace; /* spacing between lines */
int LinesPerPage; /* lines per page */
int CurrentLine; /* current line */
int LineLength; /* line length */
WORD wLines; /* number of lines to print */
WORD wIndex; /* index into lines to print */
char szLine[128]; /* buffer to store lines before printing */
TEXTMETRIC TextMetric; /* information about character size */
BOOL bAbort; /* FALSE if user cancels printing */
HWND hAbortDlgWnd;
FARPROC lpAbortDlg, lpAbortProc;
The hdcPrint variable is the handle of the printer device context. It receives the return value from the CreateDC function. The variables LineSpace and LinesPerPage hold the amount of spacing between lines and the number of lines that can be printed per page, respectively. The CurrentLine variable is a counter that keeps track of the current line on the current page. Lines of text are printed one line at a time. The dwLines variable contains the number of lines in the edit control. The TextMetric structure receives information about the font to be used to print the lines; this example uses only the members TextMetric.tmHeight and TextMetric.tmExternalLeading. The PhysPageSize structure receives the physical width and height of the printer paper. The height is used to determine how many lines per page can be printed.