http://technet.microsoft.com/zh-cn/subscriptions/a59dff1e(v=vs.71).aspx
CView::OnPreparePrinting

Called by the framework before a document is printed or previewed.

virtual BOOL OnPreparePrinting(
CPrintInfo* pInfo
);
Parameters

pInfo
Points to a CPrintInfo structure that describes the current print job.
Return Value

Nonzero to begin printing; 0 if the print job has been canceled.

Remarks

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.

DoPreparePrinting does not display the Print dialog box for a preview job. If you want to bypass the Print dialog box for a print job, check that the m_bPreview member of pInfo is FALSE and then set it to TRUE before passing it to DoPreparePrinting; reset it to FALSE afterwards.

If you need to perform initializations that require access to the CDC object representing the printer device context (for example, if you need to know the page size before specifying the length of the document), override the OnBeginPrinting member function.

If you want to set the value of the m_nNumPreviewPages or m_strPageDesc members of the pInfo parameter, do so after calling DoPreparePrinting. The DoPreparePrinting member function sets m_nNumPreviewPages to the value found in the application's .INI file and sets m_strPageDesc to its default value.

Example

Override OnPreparePrinting and call DoPreparePrinting from the override so that the framework will display a Print dialog box and create a printer DC for you.

BOOL CMyView::OnPreparePrinting(CPrintInfo *pInfo)
{
return CEditView::DoPreparePrinting(pInfo);
}
If you know how many pages the document contains, set the maximum page in OnPreparePrinting before calling DoPreparePrinting. The framework will display the maximum page number in the "to" box of the Print dialog box.

BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
//The document has 2 pages.
pInfo->SetMaxPage(2);
return CEditView::DoPreparePrinting(pInfo);

CView::OnPreparePrinting的更多相关文章

  1. 深入浅MFC

    视图类CView 在MFC"文档/视图"架构中,CView类是所有视图类的基类,它提供了用户自定义视图类的公共接口.在"文档/视图"架构中,文档负责管理和维护数 ...

  2. MFC Wizard创建的空应用程序中各个文件内容的解析

    创建的MFC应用程序名为:wd,那么: 一.wd.h解析 // wd.h : main header file for the WD application // #if !defined(AFX_W ...

  3. MFC CVIew关闭时崩溃

    记得看视频的时候老师说过    创建CView的时候,也就是创建视图的时候,不要使用  Cview      m_view;这种方式 而是使用Cview  *  pView=new   Cview() ...

  4. CView类的使用

    首先我们来写一个样例: 1.建一个win32简单应用程序,不要觉得这样就不能写出MFC程序,由于是不是MFC程序取决于调没调MFC函数. 2. 删除入口函数.仅仅留下#include "st ...

  5. MFC修改视图CView的背景颜色

    (1) 在CYournameView(就是你的视图类,以下以CDrawLineView为例)添加了一个背景颜色变量 COLORREF m_bgcolor; (2)修改这个函数: BOOL CDrawL ...

  6. CWinApp类CMultiDocTemplate类CDocument类CView类的关系

    转自:http://blog.csdn.net/bboot/article/details/26884011 不得不转,瞬间搞清了很多问题,短小精悍 1.CWinApp类   它包含并管理着应用程序的 ...

  7. MFC覆盖OnPrepareDC实现“所见即所得”打印

    附件下载:http://files.cnblogs.com/mengdejun/print.zip void CPrintView::OnPrepareDC(CDC* pDC, CPrintInfo* ...

  8. 魔改——MFC SDI 支持 内嵌 EXCEL OLE

    ==================================声明================================== 本文版权归作者所有 未经作者授权 请勿转载 保留法律追究的 ...

  9. 积累的VC编程小技巧之打印相关

    1.修改打印预览的ToolBar 为AFX_IDD_PREVIEW_TOOLBAR这个ID创建一个DialogBar.则系统就会用新创建的DialogBar代替系统默认的那个 2.关于打印 1.要打印 ...

随机推荐

  1. LeetCode 0、《两数相加》

    一.给定两个非空链表来表示两个非负整数.位数按照逆序方式存储,它们的每个节点只存储单个数字.将两数相加返回一个新的链表. 你可以假设除了数字 0 之外,这两个数字都不会以零开头. 示例: 输入:(2 ...

  2. 使用PyV8模块破解网站加密cookie

    PyV8是Chromium中内嵌的javascript引擎,号称跑的最快.PyV8是用Python在V8的外部API包装了一个python壳,这样便可以使python可以直接与javascript操作 ...

  3. 使用js实现简单放大镜的效果

    实现原理:使用2个div,里面分别放大图片和小图片,在小图片上应该还有一个遮罩层,通过定位遮罩层的位置来定位大图片的相对位置,而且,遮罩层的移动应该和大图片的移动方向相反 关键: 大图片和小图片大小比 ...

  4. pip版本及升级 pip安装指定模板

    昨天在微信聊天,一妹子9点的时候告诉我她要看书了,让明天聊,瞬间自己心中那颗学习的种子燃烧起来,思来想去还是继续学习自己之前未学好的python吧,因为之前有了点点的python基础,所以本次打算从p ...

  5. 【VC++学习笔记五】SDI|MDI的全屏显示

    一.Mainframe中添加一个记录是否全屏状态的变量BOOL m_bFullScreen. 二.工具栏添加一个按钮,进行全屏的操作,响应事件函数写在Mainframe中. 三.在响应函数中,添加如下 ...

  6. JavaScript表单项数据过滤代码

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  7. 9.9递归和动态规划(六)——打印n对括号的所有有效组合(即左右括号正确配对)

    /**  * 功能:打印n对括号的所有有效组合(即左右括号正确配对). */ 两种方法: 方法一: /** * 思路:在括号的最前面或者原有的每对括号中面插入一对括号. 至于其它任何位置.比方字符串的 ...

  8. modSecurity规则学习(一)——配置文件

    环境:modSecurity3.0,nignx1.13.8 modSecurity配置文件 1.nginx.conf server { listen ; modsecurity on; //启动mod ...

  9. js对数组进行操作

    1.数组的创建 var arrayObj = new Array(); //创建一个数组 var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限, ...

  10. java poi操作excel示例代码

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...