我的vc打印程序,打印的效果是总是重复打印,困惑!恳请高人赐教!
OnBnClickedButtonPrint()
{
CPrintDialog dlgPrint(FALSE);
if (IDCANCEL == dlgPrint.DoModal())
{
return;
}
// is a default printer set up?
HDC hdcPrinter = dlgPrint.GetPrinterDC();
if (hdcPrinter == NULL)
{
AfxMessageBox(_T("Buy a printer!"));
}
else
{
// create a CDC and attach it to the default printer
CDC dcPrinter;
dcPrinter.Attach(hdcPrinter);
// call StartDoc() to begin printing
DOCINFO docinfo;
memset(&docinfo, 0, sizeof(docinfo));
...
// if it fails, complain and exit gracefully
if (dcPrinter.StartDoc(&docinfo) < 0)
{
AfxMessageBox(_T("Printer wouldn't initalize"));
}
else
{
int nCopies = dlgPrint.GetCopies();
int nMaxPageNo = m_ListCtrlBaoBiao.GetItemCount() / ITEM_SUM;
int nValue = m_ListCtrlBaoBiao.GetItemCount() % ITEM_SUM;
if (nValue > 0)
{
++nMaxPageNo;
}
CPen penLine, *oldPen;
penLine.CreatePen(PS_SOLID, 6, RGB(0, 0, 0));
oldPen = dcPrinter.SelectObject(&penLine);
for (int nIndex = 0; nIndex < nCopies; ++nIndex)
{
// start a page
int nItemNo = 0;
for (int nPageNo = 0; nPageNo < nMaxPageNo; ++nPageNo)
{
if (dcPrinter.StartPage() < 0)
{
AfxMessageBox(_T("Could not start page"));
dcPrinter.AbortDoc();
}
else
{
// actually do some printing
PrintPage(dcPrinter, nItemNo);
dcPrinter.EndPage();
}//else
}//for
}
dcPrinter.SelectObject(oldPen);
}//else
dcPrinter.EndDoc();
ReleaseDC(&dcPrinter);
}//else
::DeleteDC(hdcPrinter);
}
我先描述一下我的问题吧:
当我选择打印一份时,打印机就打印一份--操作正常,但是当选择打印两份时,打印机就好像执行了两次打印命令似的:执行第一次,打印了两份,执行第二次,又打印了两份,结果就打印了四份。从而就出现了重复打印,我选择打印两份吗,它就给我打印了四份,气坏我了。
请路过的高人,指教我一下吧,是我的程序有问题呢,还是打印机的问题呢? 谢!谢!谢!
------解决方案--------------------帮顶。。。
------解决方案--------------------
可能是通讯的单片机没弄好吧?连发了两次数据包的缘故吧-_-!
------解决方案--------------------转到MFC区吧