www.gusucode.com > 几个VC++打印小例子-源码程序 > 几个VC++打印小例子-源码程序/code/VC_PrintTest/VC_PrintTestView.cpp

    //Download by http://www.NewXing.com
// VC_PrintTestView.cpp : implementation of the CVC_PrintTestView class
//

#include "stdafx.h"
#include "VC_PrintTest.h"

#include "VC_PrintTestDoc.h"
#include "VC_PrintTestView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CVC_PrintTestView

IMPLEMENT_DYNCREATE(CVC_PrintTestView, CEditView)

BEGIN_MESSAGE_MAP(CVC_PrintTestView, CEditView)
	//{{AFX_MSG_MAP(CVC_PrintTestView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVC_PrintTestView construction/destruction

CVC_PrintTestView::CVC_PrintTestView()
{
	// TODO: add construction code here

}

CVC_PrintTestView::~CVC_PrintTestView()
{
}

BOOL CVC_PrintTestView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	BOOL bPreCreated = CEditView::PreCreateWindow(cs);
	cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);	// Enable word-wrapping

	return bPreCreated;
}

/////////////////////////////////////////////////////////////////////////////
// CVC_PrintTestView drawing

void CVC_PrintTestView::OnDraw(CDC* pDC)
{
	CVC_PrintTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CVC_PrintTestView printing

BOOL CVC_PrintTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default CEditView preparation
	return DoPreparePrinting(pInfo);
}

void CVC_PrintTestView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView begin printing.
	CEditView::OnBeginPrinting(pDC, pInfo);
}

void CVC_PrintTestView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView end printing
	CEditView::OnEndPrinting(pDC, pInfo);
}

/////////////////////////////////////////////////////////////////////////////
// CVC_PrintTestView diagnostics

#ifdef _DEBUG
void CVC_PrintTestView::AssertValid() const
{
	CEditView::AssertValid();
}

void CVC_PrintTestView::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

CVC_PrintTestDoc* CVC_PrintTestView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVC_PrintTestDoc)));
	return (CVC_PrintTestDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CVC_PrintTestView message handlers

void CVC_PrintTestView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CEditView::OnPrepareDC(pDC, pInfo);
	//转换坐标映射方式
	pDC->SetMapMode(MM_ANISOTROPIC); 
	CSize size = CSize(800, 560); 
	//确定窗口大小
	pDC->SetWindowExt(size); 
	//得到实际设备每逻辑英寸的象素数量
	int xLogPixPerInch = pDC-> GetDeviceCaps(LOGPIXELSX); 
	int yLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSY); 
	//得到设备坐标和逻辑坐标的比例
	long xExt = (long)size.cx * xLogPixPerInch/96 ; 
	long yExt = (long)size.cy * yLogPixPerInch/96 ;
	//确定视口大小
	pDC->SetViewportExt((int)xExt, (int)yExt); 

}