Click to See Complete Forum and Search --> : PRINTING: how can I print multiple pages


Danielle Harvey
May 19th, 1999, 08:06 PM
I don't understand how to print multiple pages of text. I have nothing in my OnBeginPrinting or OnEndPrinting functions and my OnPrint and OnDraw functions are essentially,

OnPrint(CDC *pDC, CPrintInfo* pInfo)
{
OnDraw(pDC);
}

OnDraw(CDC *pDC)
{
for (int y=0; y<500; y+=20)
pDC->TextOut(5, y, "Text");
}

How can I put unique text on page 2? If I declare SetMaxPage(2) I get the same text on the second page and this is really frustrating. How can I call a page break and continue text on the next page?

Any response any one can give me will be greatly appreciated.

Daniel Schmid
May 20th, 1999, 12:34 AM
The printing mechanism works like this: The MFC Framework first calls the

OnPreparePrinting(CPrintInfo* pInfo)
- Here you calculate or define the maximum number of pages you want to print and write the value to pInfo->SetMaxPage(numofpages).
- This method then calls the Print Configuration Dialog and you can choose if you want to print a particular page or everything, a.s.o

Then the next method is called:
OnBeginPrinting(CDC* /*pDC*/, CPrintInfo*/*pInfo*/)
- Here you can create Fonts and other definition stuff you have to do just only once in the whole printing process...

Finally for every single page that has to be printed, the MFC framework calls the method

OnPrint(CDC* pDC, CPrintInfo* pInfo)

NOW HERE's YOUR POINT:
Within this method, you have to check the page that is to be printed with the current call to this method. You find this information in

pInfo->m_nCurPage

So if you just want to write different text on two pages, you make a decision statement, maybe like

switch (pInfo->m_nCurPage)

and do a block which is responsible to print the text on the according page...

if you have a table of data you want to print, you do a for(...) loop and calculate the starting point and the end point of the loop according to the page you want to print.

Just something about OnPrint and OnDraw:
OnPrint is only called when there is a printjob to be done. If there is no OnPrint method, the framework automatically calls the OnDraw method and just passes the according DeviceContext...

I hope you can do some more steps with this hints...

Regards
Daniel