int iFirst = (pInfo->m_nCurPage - 1) * m_iItemXPage;
int iLast = (pInfo->m_nCurPage) * m_iItemXPage;
int y = rcPrint.top;
int x = rcPrint.left;
CFont * oft = pDC->SelectObject(&m_ftPrint);
CRect rc1;
CString cs;
int iMax = m_iTotItem;
for (int i = iFirst; i < iLast; i++)
{
bool bIs = i < iMax;
int box = 0;
for (int t = 0; t < m_iNumCol; t++)
{
rc1.SetRect(rcPrint.left+m_pDx[t], y, rcPrint.left+m_pDx[t+1], y+m_szFtPrint.cy);
if (bIs)
{
cs = m_pList->GetItemText(i, t);
UINT ftm = DT_LEFT;
if (m_pFormat[t]&HDF_CENTER)
ftm = DT_CENTER;
else if (m_pFormat[t]&HDF_RIGHT)
ftm = DT_RIGHT;
int box = 0;
CRect rc1;
int y = rcPage.top;
for (int t = 0; t < m_iNumCol; t++)
{
rc1.SetRect(rcPage.left+m_pDx[t], y, rcPage.left+m_pDx[t+1], y+m_szFtPrint.cy);
CString cs = m_pColTitle[t] ? m_pColTitle[t] : "";
pDC->Rectangle(rc1);
UINT ftm = DT_LEFT;
if (m_pFormat[t]&HDF_CENTER)
ftm = DT_CENTER;
else if (m_pFormat[t]&HDF_RIGHT)
ftm = DT_RIGHT;
class CListCtrlPrint : public CPrintObj
{
public:
CListCtrlPrint();
virtual ~CListCtrlPrint();
CRect m_rcMarginMM; // contain the margins in millimeters
CFont m_ftPrint, m_ftHead, m_ftFoot; // fonts used for printing
CSize m_szFtPrint, m_szFtHead, m_szFtFoot; // sizes of fonts (in device unit)
int *m_pDx, *m_pFormat; // datas about column size and format (center, right ..)
char **m_pColTitle; // columns titles
int m_iItemXPage, m_iNumCol, m_iTotItem; // number of item in page, of columns and of tot number of items in list control
CListCtrl *m_pList; // pointer of the list ctrl
CString m_csPageHead; // text of header
CString m_csPageFooter; // text of footer
CString m_csPage; // format of page number / tot pages (ex. page %d of %d)
CString m_csFtHead, m_csFtFoot, m_csFtPrint; // fonts type names
int m_iFtHead, m_iFtFoot, m_iFtPrint; // fonts sizes
CSize m_szFoot; // internal use
// this subtracts the margins from the page size
void SubtractMargin(CDC *pDC, CRect &rc);
// virtual overridden from base class; same meaning of CView's one
void OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo);
void OnEndPrinting(CDC *pDC, CPrintInfo *pInfo);
bool OnPreparePrinting(CPrintInfo *pInfo, bool bPrintPreview = false);
void OnPrint(CDC* pDC, CPrintInfo *pInfo);
// function self explicative; the items will be printed in the OnPrint function
// if bCalc is true, the function is called to compute the space for items and so
// no printing is needed, but only to return the size used and to subtract from the
// rcpage the space used
CSize PrintListFoot(CDC *pDC, CRect &rcPage, bool bCalc);
CSize PrintListHead(CDC *pDC, CRect &rcPage, bool bCalc);
CSize PrintPageFoot(CDC *pDC, CRect &rcPage, bool bCalc);
CSize PrintPageHead(CDC *pDC, CRect &rcPage, const int nPage, const int iMaxPage, bool bCalc);
};
// disable main window while printing & init printing status dialog
CString csFormat, cs, strTemp;
AfxGetMainWnd()->EnableWindow(FALSE);
// CPrintStatus dlgPrintStatus(pParent);
// cs.Format("Stampa di %s in corso ..", strTitle);
// dlgPrintStatus.SetWindowText(cs);
// start document printing process
if (dcPrint.StartDoc(&docInfo) == SP_ERROR)
{
// enable main window before proceeding
AfxGetMainWnd()->EnableWindow(TRUE);
// cleanup and show error message
OnEndPrinting(&dcPrint, &printInfo);
// dlgPrintStatus.DestroyWindow();
dcPrint.Detach(); // will be cleaned up by CPrintInfo destructor
AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
return;
}
// Guarantee values are in the valid range
UINT nEndPage = printInfo.GetToPage();
UINT nStartPage = printInfo.GetFromPage();
// cleanup document printing process
if (!bError)
dcPrint.EndDoc();
else
dcPrint.AbortDoc();
AfxGetMainWnd()->EnableWindow(); // enable main window
OnEndPrinting(&dcPrint, &printInfo); // clean up after printing
// dlgPrintStatus.DestroyWindow();
dcPrint.Detach(); // will be cleaned up by CPrintInfo destructor
}
}
// Default to one page printing if doc length not known
if (pInfo != NULL)
pInfo->m_bContinuePrinting =
(pInfo->GetMaxPage() != 0xffff || (pInfo->m_nCurPage == 1));
}