Add Variables for Printing

You need to declare new variables to support printing. Add the following declarations to the beginning of your source file:

HDC hPr; /* handle for printer device context */

int LineSpace; /* spacing between lines */

int LinesPerPage; /* lines per page */

int CurrentLine; /* current line */

int LineLength; /* line length */

DWORD dwLines; /* number of lines to print */

DWORD dwIndex; /* index into lines to print */

char pLine[128]; /* buffer to store lines before printing */

TEXTMETRIC TextMetric; /* information about character size */

POINT PhysPageSize; /* information about the page */

BOOL bAbort; /* FALSE if user cancels printing */

HWND hAbortDlgWnd;

FARPROC lpAbortDlg, lpAbortProc;

The hPr variable is the handle for the printer device context. It receives the return value from the CreateDC function call. 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 holds 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 TextMetric.tmHeight and TextMetric.tmExternalLeading fields. 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.