关于打印:每次打印都多走一张白纸,为什么??(虽然是VC程序,但是逻辑问题,帮忙看看)(100分)

W

wukw

Unregistered / Unconfirmed
GUEST, unregistred user!
在OnPrint()函数的末尾:

pDC->EndPage();
pDC->StartPage();

这样的结果就是,每次打印都多走一张白纸,为什么??
我也不傻,这样写:(最奇怪的是,如下写,居然不打印了!!!)
{
pDC->EndPage();
if (n<nPage) {
pDC->StartPage();
}
}
其中n是当前页数(根据要打印的数据量计算得来,而不是CPrintInfo的成员),nPage是总页数。意思是,打印完最后一页,EndPage以后,就不要StartPage了。可是那样的话,整个程序根本就不打印了,这是为什么???谢谢 !

整个OnPrint函数如下:
void CQiMeiView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CPoint ptCurPos(0,0);
// current printing position
CRect rectDrawArea;
// printing area
int iVert,iHorz;
// sizeof avialiable printing area
// set map mode to 0.1 millimetric &amp;
get avialiable area
pDC->SetMapMode(MM_LOMETRIC);
iVert=pDC->GetDeviceCaps(VERTSIZE)*10;
iHorz=pDC->GetDeviceCaps(HORZSIZE)*10;
rectDrawArea=CRect(0,0,iHorz,-iVert);
TEXTMETRIC tm;
pDC->GetTextMetrics(&amp;tm);
// 得到字体结构
int nHeight=tm.tmHeight+tm.tmExternalLeading;
// 得到字体高度48
int nWidth=tm.tmMaxCharWidth;
// 得到字体最大宽度42
int j=m_strPrintArray.GetSize();

if (m_nPrintMethod==1) { // 全班打印
Pen.CreatePen(PS_SOLID,3,RGB(255,0,0));
pDC->SelectObject(&amp;Pen);

// 初始化左上坐标
rectDrawArea=CRect(100,-100, iHorz, -iVert);
CString str="雅思 " + m_strClassName + " 全体状况表";
pDC->DrawText(str, &amp;rectDrawArea, DT_WORDBREAK);
// 打印统计数据
UpdateData();

CString str2 = m_strAllNumber + " " + m_strSchoolingFee + " " + m_strProcedureFee + " " + m_strCenterFee + " " + m_strSchoolFee + " " + m_strInvoiceNumber + " " + m_strBooksFee;

ptCurPos.Offset(100, -100-2*nHeight);

rectDrawArea.top=ptCurPos.y;
// reset draw rect
pDC->DrawText(str2, &amp;rectDrawArea, DT_WORDBREAK);
ptCurPos.Offset(0 ,-3*nHeight);
int nPage = j/(30*12)+1;
// 判断有多少页
for (int n=1;
n<=nPage;
n++) // 按页循环打印
{
// draw rectangle
if (n!=nPage)
pDC->Rectangle(95, ptCurPos.y+2, 2600, ptCurPos.y-nHeight*(2+30)-2);
else
pDC->Rectangle(95, ptCurPos.y+2, 2600, ptCurPos.y-nHeight*(2+j/12%30)-2);
// draw column head
int iColumnSize=m_astrColumn.GetSize();
for(int iColumn=0;iColumn<iColumnSize;iColumn++)
{
rectDrawArea.left=ptCurPos.x;
rectDrawArea.top=ptCurPos.y;
pDC->DrawText(m_astrColumn[iColumn], &amp;rectDrawArea, DT_WORDBREAK);
// move cursor
ptCurPos.Offset(5*nWidth,0);
}
ptCurPos.x=0;
ptCurPos.Offset(100,-2*nHeight);
int nItems=0;
if (n!=nPage)
nItems = n*30*12;
else
nItems = j;//%(30*12-1);
for(int i=(n-1)*30*12 ;
i<nItems;
i++)
{
// move cursor
rectDrawArea.left=ptCurPos.x;
rectDrawArea.top=ptCurPos.y;
// draw content
pDC->DrawText(m_strPrintArray, &amp;rectDrawArea, DT_WORDBREAK);
// move cursor
ptCurPos.Offset(5*nWidth,0);
// reset cursor to x0
if((i+1)%12==0)
{
// draw line
pDC->MoveTo(95, ptCurPos.y+2);
pDC->LineTo(2600, ptCurPos.y+2);
// new line
ptCurPos.x=0;
ptCurPos.Offset(100,-nHeight);
}
}
pDC->EndPage();
// pDC->StartPage();
if (n<nPage) {
pDC->StartPage();
}
ptCurPos = (0,0);
ptCurPos.Offset(100, -100-2*nHeight);

}
}
}
 

CDC dcPrinter;
dcPrinter.Attach(hdcPrinter);
// call StartDoc() to begin
printing
do
CINFOdo
cinfo;
memset(&amp;docinfo, 0, sizeof(docinfo));
do
cinfo.cbSize = sizeof(docinfo);
do
cinfo.lpszDocName = _T("CDC::StartDoc() Code Fragment");
// if it fails, complain and exit gracefully
if (dcPrinter.StartDoc(&amp;docinfo) < 0)
{
MessageBox(_T("Printer wouldn't initalize"));
}
else
{
// start a page
if (dcPrinter.StartPage() < 0)
{
MessageBox(_T("Could not start page"));
dcPrinter.AbortDoc();
}
else
{
// actuallydo
some printing
CGdiObject* pOldFont = dcPrinter.SelectStockObject(SYSTEM_FONT);
dcPrinter.TextOut(50, 50, _T("Hello World!"), 12);
dcPrinter.EndPage();
dcPrinter.EndDoc();
dcPrinter.SelectObject(pOldFont);
}
 
接受答案了.
 
顶部