zoukankan      html  css  js  c++  java
  • VC:基于文档的打印

           打印过程:

    OnPreparePrinting()函数进行打印中一些信息的设置。

    OnBeginPrinting()函数创建打印资源。

    OnPrepareDC()函数设置具体打印一页时的信息。

    调用OnPrint()函数打印一页。

    1、在利用向导生成单文档和多文档应用程序的过程中,用户可以选择应用程序是否支持打印和打印预览功能。(在向导的第4部)

    2、将默认的MM_TEXT模式转换为MM_LOENGLISH模式。方法如下:SetMapMode(MM_LOENGLISH);

    3、多页打印:

           在打印或打印预览时可以在OnBeginPrinting()函数中设置打印的页数。

    如:

    void CTestView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)

    {

           // TODO: add extra initialization before printing

           CTestDoc *pDoc=GetDocument();

           ASSERT_VALID(pDoc);

           //得到打印纸的垂直分辨率

           int height=pDC->GetDeviceCaps(VERTRES);

           //得到打印纸上一英寸可打印点数目

           int ypixnum=pDC->GetDeviceCaps(LOGPIXELSY);

           //设置页数

           pInfo->SetMaxPage(3*ypixnum*drawheight/height+1);

    }

           解决第1、2页面内容相同的问题:即设置页面顶部信息。

    如下:

    void CTestView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)

    {

           // TODO: Add your specialized code here and/or call the base class

           if(pDC->IsPrinting())

           {

                  pDC->SetMapMode(MM_LOENGLISH);

                  //得到打印纸的垂直分辨率

                  int height=pDC->GetDeviceCaps(VERTRES);

                  //得到当前一页的坐标

                  int y=height*(pInfo->m_nCurPage-1);

                  pDC->SetViewportOrg(0,-y);

           }

           CView::OnPrepareDC(pDC, pInfo);

    }

  • 相关阅读:
    数据库性能优化一:数据库自身优化(大数据量)
    在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。Microsoft SQL Server,错误: 10061
    跨域请求解决方案
    转:intent简介
    转:屏幕适配
    java.util.concurrent.RejectedExecutionException
    转:Android事件传递机制
    转:通过重写ViewGroup学习onMeasure()和onLayout()方法
    android:layout_weight属性详解
    转:Android自动测试之Monkey工具
  • 原文地址:https://www.cnblogs.com/shenchao/p/2941093.html
Copyright © 2011-2022 走看看