打印时产生了循环。

duron1000 2004-04-28 07:45:00
我的程序是MFC单文档,VIEW的基类是LISTVIEW,为了打印LISTVIEW中的内容,写了一个OutputReport(CDC* pDC, CPrintInfo* pInfo)函数,在VIEW类的OnPrint(CDC* pDC, CPrintInfo* pInfo)函数中调用。打印页数为1页时,打印预览和打印结果都是对的;当打印页数超过1页时,在打印预览中显示的打印页数是对的,点击打印后,出现对话框: 在EMPSON打印机上打印第 N 页,N的值一直往上加,到几千还未停止,直到内存不足。请教是什么原因啊?
...全文
142 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
duron1000 2004-04-28
  • 打赏
  • 举报
回复
我在OnBeginPrinting(CDC* pDC, CPrintInfo* )中执行PageCount=GetPrintPageMax( pDC, pInfo);pInfo->SetMaxPage(PageCount);
GetPrintPageMax是自定义的用于计算页数的函数,又在OutputReport中去掉pInfo->SetMaxPage(pInfo->m_nCurPage+1);问题似乎已解决。先充分测试一下。
duron1000 2004-04-28
  • 打赏
  • 举报
回复
在View类里的OnBeginPrinting函数加入pInfo->SetMaxPage()设置最大的页数。
///////
这个办法可以试一下。
TScom 2004-04-28
  • 打赏
  • 举报
回复
如果当前打印的行数大于NumPerPage时,pInfo->SetMaxPage(pInfo->m_nCurPage+1);break;
--------------------------------------------------------------------------------
这样的话,最大的页数就会一直加一。

在View类里的OnBeginPrinting函数加入pInfo->SetMaxPage()设置最大的页数。
duron1000 2004-04-28
  • 打赏
  • 举报
回复
那为什么打印预览中是正确的?打印预览和打印都是调用ONPRINT函数的啊.在OnPreparePrinting()中如何判断什么时候该pInfo->SetMaxPage(pInfo->m_nCurPage+1);如何在所有实际页数发送给打印机后停止发送?
swbreath 2004-04-28
  • 打赏
  • 举报
回复
pInfo->SetMaxPage(pInfo->m_nCurPage+1);这个函数要在OnPreparePrinting(CPrintInfo* pInfo)里面调用
duron1000 2004-04-28
  • 打赏
  • 举报
回复
OnPreparePrinting(CPrintInfo* pInfo)?
没有CDC* pDC参数啊?
  我在OutputReport(CDC* pDC, CPrintInfo* pInfo)函数里自己画了一张表格,并将LISTVIEW中的内容DRAWTEXT进去,根据打印纸张的高度(nHorRes = pDC->GetDeviceCaps(HORZRES); )和每行的高度计算出每页的行数NumPerPage.如果当前打印的行数大于NumPerPage时,pInfo->SetMaxPage(pInfo->m_nCurPage+1);break;即换页.打印预览是对的,可以翻页.开始打印时却出现循环,真奇怪.
swbreath 2004-04-28
  • 打赏
  • 举报
回复
Called by the framework before a document is printed or previewed. The default implementation does nothing.

You must override this function to enable printing and print preview. Call the DoPreparePrinting member function, passing it the pInfo parameter, and then return its return value; DoPreparePrinting displays the Print dialog box and creates a printer device context. If you want to initialize the Print dialog box with values other than the defaults, assign values to the members of pInfo. For example, if you know the length of the document, pass the value to the SetMaxPage member function of pInfo before calling DoPreparePrinting. This value is displayed in the To: box in the Range portion of the Print dialog box.

swbreath 2004-04-28
  • 打赏
  • 举报
回复
设置页面不能在OnPrint中使用,应该在OnPreparePrinting中设置吧

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧