📄 multiprintview.cpp
字号:
// MultiPrintView.cpp : implementation of the CMultiPrintView class
//
#include "stdafx.h"
#include "MultiPrint.h"
#include "MultiPrintDoc.h"
#include "MultiPrintView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMultiPrintView
IMPLEMENT_DYNCREATE(CMultiPrintView, CView)
BEGIN_MESSAGE_MAP(CMultiPrintView, CView)
//{{AFX_MSG_MAP(CMultiPrintView)
// 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, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMultiPrintView construction/destruction
CMultiPrintView::CMultiPrintView()
{
// TODO: add construction code here
}
CMultiPrintView::~CMultiPrintView()
{
}
BOOL CMultiPrintView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMultiPrintView drawing
void CMultiPrintView::OnDraw(CDC* pDC)
{
int i;
int j;
CMultiPrintDoc* pDoc = GetDocument();
j = pDoc->m_retangleArr.GetUpperBound();
for (i = 0; i < j; i++)
{
pDC->Rectangle(pDoc->m_retangleArr[i]);
}
}
/////////////////////////////////////////////////////////////////////////////
// CMultiPrintView printing
BOOL CMultiPrintView::OnPreparePrinting(CPrintInfo* pInfo)
{
CMultiPrintDoc* pDoc = GetDocument();
pInfo->SetMaxPage(pDoc->m_retangleArr.GetUpperBound() /
CMultiPrintDoc::nLinesPerPage + 1);
return DoPreparePrinting(pInfo);
}
void CMultiPrintView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMultiPrintView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMultiPrintView diagnostics
#ifdef _DEBUG
void CMultiPrintView::AssertValid() const
{
CView::AssertValid();
}
void CMultiPrintView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMultiPrintDoc* CMultiPrintView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMultiPrintDoc)));
return (CMultiPrintDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMultiPrintView message handlers
void CMultiPrintView::PrintPageHeader(CDC *pDC)
{
CString str;
CPoint point(0, 0);
pDC->TextOut(point.x, point.y, "打印");
point += CSize(720, -720);
str.Format("%6.6s %6.6s %6.6s %6.6s %6.6s",
"Index", "Left", "Top", "Right", "Bottom");
pDC->TextOut(point.x, point.y, str);
}
void CMultiPrintView::PrintPageFooter(CDC *pDC)
{
CString str;
CPoint point(0, -14400); // Move 10 inches down
CMultiPrintDoc* pDoc = GetDocument();
str.Format("Document %s", (LPCSTR) pDoc->GetTitle());
pDC->TextOut(point.x, point.y, str);
str.Format("Page %d", m_nPage);
CSize size = pDC->GetTextExtent(str);
point.x += 11520 - size.cx;
pDC->TextOut(point.x, point.y, str); // right-justified
}
void CMultiPrintView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
pDC->SetMapMode(MM_LOENGLISH);
//CView::OnPrepareDC(pDC, pInfo);
}
void CMultiPrintView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
//CView::OnPrint(pDC, pInfo);
int i, nStart, nEnd, nHeight;
CString str;
CPoint point(720, -1440);
CFont font;
TEXTMETRIC tm;
pDC->SetMapMode(MM_TWIPS);
CMultiPrintDoc* pDoc = GetDocument();
m_nPage = pInfo->m_nCurPage; // for PrintPageFooter抯 benefit
nStart = (m_nPage - 1) * CMultiPrintDoc::nLinesPerPage;
nEnd = nStart + CMultiPrintDoc::nLinesPerPage;
// 14-point fixed-pitch font
font.CreateFont(-280, 0, 0, 0, 400, FALSE, FALSE,
0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_MODERN, "Courier New");
// Courier New is a TrueType font
CFont* pOldFont = (CFont*) (pDC->SelectObject(&font));
PrintPageHeader(pDC);
pDC->GetTextMetrics(&tm);
nHeight = tm.tmHeight + tm.tmExternalLeading;
for (i = nStart; i < nEnd; i++) {
if (i > pDoc->m_retangleArr.GetUpperBound()) {
break;
}
str.Format("%6d %6d %6d %6d %6d", i + 1,
pDoc->m_retangleArr[i].left,
pDoc->m_retangleArr[i].top,
pDoc->m_retangleArr[i].right,
pDoc->m_retangleArr[i].bottom);
point.y -= nHeight;
pDC->TextOut(point.x, point.y, str);
}
PrintPageFooter(pDC);
pDC->SelectObject(pOldFont);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -