Printing Problems
-
When I was stepping thru this code to see why it was not working I found that the pInfo->m_nCurPage was not being updated. Any idea why? I did not over ride OnBeginPrinting() or OnEndPrinting() CMyView is derived from CEditView
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
CString string;
int index=0; // Location of the page breaks
int pages=0;
m_pbIndex.SetAt(pages, index);// Get the number of pages to be printed GetWindowText(string); while(index >= 0) { // find the page breaks and store // the location in the array index = string.Find("\\f", index+1); pages++; m\_pbIndex.SetAt(pages, index); } pInfo->SetMinPage(1); pInfo->SetMaxPage(pages - 1); return DoPreparePrinting(pInfo);
}
void CMyView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// The rectangle on my sheet of paper
m_nPageHeight = pDC->GetDeviceCaps(VERTRES);
pInfo->m_rectDraw.SetRect(0, 0, pDC->GetDeviceCaps(HORZRES), m_nPageHeight);// Adjusted for Margins double LeftOffset = 0.6; // in imperial inches double TopOffset = 0.5; double RightOffset = 0.5 ; double BottomOffset = 0.5 ; pInfo->m\_rectDraw.DeflateRect((int)(pDC->GetDeviceCaps(LOGPIXELSX) \* LeftOffset), (int)(pDC->GetDeviceCaps(LOGPIXELSY) \* TopOffset), (int)(pDC->GetDeviceCaps(LOGPIXELSX) \* RightOffset), (int)(pDC->GetDeviceCaps(LOGPIXELSY) \* BottomOffset)); // Adjust for the correct sheet pDC->SetViewportOrg(0, (pInfo->m\_nCurPage-1)\*m\_nPageHeight); // Print the page CMyDoc\* pDoc = GetDocument(); PrintPage(pDoc, pDC, pInfo);
}
void CMyView::PrintPage(CJulieDoc* pDoc, CDC* pDC, CPrintInfo* pInfo)
{
int beg;
int end;CString string; GetWindowText(string); beg = pbIndex.GetAt(pInfo->m\_nCurPage-1); end = pbIndex.GetAt(pInfo->m\_nCurPage); string = string.Mid(beg, end); pDC->DrawText(string, pInfo->m\_rectDraw, DT\_EXTERNALLEADING && DT\_LEFT && DT\_NOCLIP);
}
As always, Thank You
-
When I was stepping thru this code to see why it was not working I found that the pInfo->m_nCurPage was not being updated. Any idea why? I did not over ride OnBeginPrinting() or OnEndPrinting() CMyView is derived from CEditView
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
CString string;
int index=0; // Location of the page breaks
int pages=0;
m_pbIndex.SetAt(pages, index);// Get the number of pages to be printed GetWindowText(string); while(index >= 0) { // find the page breaks and store // the location in the array index = string.Find("\\f", index+1); pages++; m\_pbIndex.SetAt(pages, index); } pInfo->SetMinPage(1); pInfo->SetMaxPage(pages - 1); return DoPreparePrinting(pInfo);
}
void CMyView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// The rectangle on my sheet of paper
m_nPageHeight = pDC->GetDeviceCaps(VERTRES);
pInfo->m_rectDraw.SetRect(0, 0, pDC->GetDeviceCaps(HORZRES), m_nPageHeight);// Adjusted for Margins double LeftOffset = 0.6; // in imperial inches double TopOffset = 0.5; double RightOffset = 0.5 ; double BottomOffset = 0.5 ; pInfo->m\_rectDraw.DeflateRect((int)(pDC->GetDeviceCaps(LOGPIXELSX) \* LeftOffset), (int)(pDC->GetDeviceCaps(LOGPIXELSY) \* TopOffset), (int)(pDC->GetDeviceCaps(LOGPIXELSX) \* RightOffset), (int)(pDC->GetDeviceCaps(LOGPIXELSY) \* BottomOffset)); // Adjust for the correct sheet pDC->SetViewportOrg(0, (pInfo->m\_nCurPage-1)\*m\_nPageHeight); // Print the page CMyDoc\* pDoc = GetDocument(); PrintPage(pDoc, pDC, pInfo);
}
void CMyView::PrintPage(CJulieDoc* pDoc, CDC* pDC, CPrintInfo* pInfo)
{
int beg;
int end;CString string; GetWindowText(string); beg = pbIndex.GetAt(pInfo->m\_nCurPage-1); end = pbIndex.GetAt(pInfo->m\_nCurPage); string = string.Mid(beg, end); pDC->DrawText(string, pInfo->m\_rectDraw, DT\_EXTERNALLEADING && DT\_LEFT && DT\_NOCLIP);
}
As always, Thank You