The study of chapter 13 in programming windows with mfc-printing with document and views

1.The base architecture:

    CDC dc(this);
    CPrintDialog dlg(False);
    //dlg.GetDefault();
    //if(dlg.DoModal()==IDOK)
    dc.Attach(dlg.GetPrintDC())

    DOCINFO di;
    ::ZeroMemory(&di,sizeof(DOCINFO));
    di.cbSize=sizeof(DOCINFO)
    di.lpszDocName=_T("ddddddddd");
    if(dc.StatDoc(&di))
    int nContinue=true;

    for(int i=0;i<nPage&&nContinue;i++)
    {
            dc.StartPage();
            //
            if(dc.EndPage()<0)
             nContinue=false;
    }
    if(nContinue)
        dc.EndDoc();
    else
        dc.Abort();

 

2.Abort processure:[CView]

    int CALLBACK AbortProc(HDC hDC,UNIT nCode)

    {

           MSG msg;

           while(!bUserAbort&&::PeekMessage(&msg,0,0,PM_NOREMOVE)

                    AfxGetThread()->PumpMessage();

           return !bUserAbort;

    }

 

3.MFC print Architecture

   OnPreparePrinting(CDC *pDC,CPrintInfo *pf)  

   {

          pf->SetMaxPage(3);

          return DoPreparePrinting(pDC,pf);

   } 

   OnBeginPrinting(CDC *pDC,CPrintInfo *pf)

   {

          int nPageHeight=pf->GetDeviceCaps(VERTRES);

          int nDocLength=pf->GetDocLength();

          int nMaxPage=max(1,(nDocLength+nPageHeight-1)/nPageHeight);

          pf->SetMaxPage(nMaxPage);

   }

If it's impossible (or simply inconvenient) to determine the document length before printing begins, you can perform print-time pagination by overriding OnPrepareDC and setting CPrintInfo::m_bContinuePrinting to TRUE or FALSE each time OnPrepareDC is called. An m_bContinuePrinting value equal to FALSE terminates the print job. If you don't call SetMaxPage, the framework assumes the document is only one page long. Therefore, you must override OnPrepareDC and set m_bContinuePrinting to print documents that are more than one page long if you don't set the maximum page number with SetMaxPage.

 

   OnPrepareDC(CDC *pDC,CPrintInfo *pf)  //you need to override OnPrepareDC only if you use OnDraw to draw to both the screen and the printed page

   {

         CView::OnPrepareDC(pDC,pf);

         if(pDC->isPrinting())

         {

            //.........

            int y=(pf->m_nCurPage-1)/nPageHeight;

            pDC->SetViewOrg(0,-y);

         }           

   }

   OnPrint(CDC *pDC,CPrintInfo *pf)         //It's usually more practical to put printer output logic in OnPrint and screen logic in OnDraw.

   {

        PrintHeader(pDC);

        PrintPageNumber(pDC,pf->m_nCurPage);

        // Set the viewport origin and/or clipping region before

        OnDraw(pDC);

   }

   OnEndPrinting(CDC *pDC,CPrintInfo *pf)

  

4.PrintPreview

    CView::OnFilePrintPreview       ID=ID_FILE_PRINT_PREVIEW

    void CMyView::OnEndPrintPreview (CDC* pDC, CPrintInfo* pInfo,
    POINT point, CPreviewView* pView)
    {
        UINT nPage = pInfo->m_nCurPage;
        POINT pt;
         // Convert nPage into a scroll position in pt.
        ScrollToPosition (pt);
        CScrollView::OnEndPrintPreview (pDC, pInfo, point, pView); 
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风水月

从心底相信自己是成功的第一步

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值