Jim Weiss
April 21st, 1999, 11:19 AM
I have fallen into the MFC multiple page printing trap. I have an MDI app with a form view for the main view with several edit boxes for users to fill in. I've created a "virtual print document" in OnPrint (code listed below) that creates a CRect object and fills it with the contents of the edit boxes using DrawText (linking all the boxes and dividing them with double carriage returns). This creates a document that's never on screen except for print preview. And it works great for printing a single page. My problem is, how do I divide this "virtual print document" into pages to print multiple pages if the contents of the edit boxes push the page count over one? I've heard that I can use StartPage and EndPage to divide this text into pages in some kind of loop but can't figure it out. What's listed below is all the printing code I have besides the default printing functions. What can I add to this code to get it to divide into multiple pages? Also, am I putting this code in the right place? Could I put it in OnDraw so OnPreparePrinting would have access to it to find out how many pages there are to be able to SetMaxPage?
void CCharmaView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
CRect rc;
CFont myfont;
rc.SetRect(200,200,2200,3300);
myfont.CreateFont(55,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_MODERN,"Arial");
CFont *pOldFont = pDC->SelectObject(&myfont);
pDC->DrawText(m_edit1 + "\r\r" + m_edit2 + m_edit3...[and so on - several edit boxes linking together], &rc, DT_WORDBREAK);
pDC->SelectObject(pOldFont);
myfont.DeleteObject();
}
What can I add to this to divide any text it creates over one page into more pages? Any help would be greatly appreciated. Thanks in advance.
void CCharmaView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
CRect rc;
CFont myfont;
rc.SetRect(200,200,2200,3300);
myfont.CreateFont(55,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_MODERN,"Arial");
CFont *pOldFont = pDC->SelectObject(&myfont);
pDC->DrawText(m_edit1 + "\r\r" + m_edit2 + m_edit3...[and so on - several edit boxes linking together], &rc, DT_WORDBREAK);
pDC->SelectObject(pOldFont);
myfont.DeleteObject();
}
What can I add to this to divide any text it creates over one page into more pages? Any help would be greatly appreciated. Thanks in advance.