⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myprintview.cpp

📁 这个是我们学校用的VC++教案
💻 CPP
字号:
// MyPrintView.cpp : implementation of the CMyPrintView class
//

#include "stdafx.h"
#include "MyPrint.h"

#include "MyPrintDoc.h"
#include "MyPrintView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyPrintView

IMPLEMENT_DYNCREATE(CMyPrintView, CView)

BEGIN_MESSAGE_MAP(CMyPrintView, CView)
	//{{AFX_MSG_MAP(CMyPrintView)
	ON_WM_LBUTTONDOWN()
	ON_WM_RBUTTONDOWN()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyPrintView construction/destruction

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

}

CMyPrintView::~CMyPrintView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyPrintView drawing

void CMyPrintView::OnDraw(CDC* pDC)
{
	CMyPrintDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CFont fnt;
	fnt.CreateFont(100,0,0,0,0,0,0,0,0,0,0,0,0,0);//创建自定义字体,字体高度为100     
	CFont* pOldFnt=(CFont*)pDC->SelectObject(&fnt);
	CBrush bru(HS_DIAGCROSS,RGB(0,0,255));
	CBrush* pOldBru=(CBrush*)pDC->SelectObject(&bru);
	CString strNum;
	strNum.Format(" Total: %d ",pDoc->m_numRects);
	pDC->SetMapMode(MM_LOENGLISH);	//一般在OnPrepareDC()成员函数中设置
	for(int i=0;i<pDoc->m_numRects;++i)
	{
		pDC->Rectangle(100,-(20+250*i),500,-(220+250*i)); //显示矩形
		pDC->TextOut(130,-(20+250*i+50),strNum);  //显示矩形数目
	}
	pDC->SelectObject(pOldBru);
	pDC->SelectObject(pOldFnt);
}

/////////////////////////////////////////////////////////////////////////////
// CMyPrintView printing

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

void CMyPrintView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// TODO: add extra initialization before printing
	CMyPrintDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	int pageHeight=pDC->GetDeviceCaps(VERTRES);
	int logPixelsY=pDC->GetDeviceCaps(LOGPIXELSY);
	int rectHeight=(int)(2.5*logPixelsY);
	int numPages=pDoc->m_numRects*rectHeight/pageHeight+1;
	pInfo->SetMaxPage(numPages);
}

void CMyPrintView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyPrintView diagnostics

#ifdef _DEBUG
void CMyPrintView::AssertValid() const
{
	CView::AssertValid();
}

void CMyPrintView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CMyPrintView message handlers

void CMyPrintView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CMyPrintDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	pDoc->m_numRects++;
	Invalidate();
	
	CView::OnLButtonDown(nFlags, point);
}

void CMyPrintView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CMyPrintDoc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	if(pDoc->m_numRects>0)
		{
		pDoc->m_numRects--;
		Invalidate();
	}

	CView::OnRButtonDown(nFlags, point);
}

void CMyPrintView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pDC->IsPrinting())
	{
		int pageHeight=pDC->GetDeviceCaps(VERTRES);
		int originY=pageHeight*(pInfo->m_nCurPage-1);
		pDC->SetViewportOrg(0,-originY);
	}
	CView::OnPrepareDC(pDC, pInfo);
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -