📄 examle1view.cpp
字号:
// Examle1View.cpp : implementation of the CExamle1View class
//
#include "stdafx.h"
#include "Examle1.h"
#include "PreView.h"
#include "Examle1Doc.h"
#include "Examle1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExamle1View
IMPLEMENT_DYNCREATE(CExamle1View, CView)
BEGIN_MESSAGE_MAP(CExamle1View, CView)
//{{AFX_MSG_MAP(CExamle1View)
// 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,OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExamle1View construction/destruction
CExamle1View::CExamle1View()
{
// TODO: add construction code here
}
CExamle1View::~CExamle1View()
{
}
BOOL CExamle1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CExamle1View drawing
void CExamle1View::OnDraw(CDC* pDC)
{
m_titlefont.CreatePointFont(200,"宋体",pDC);
m_bodyfont.CreatePointFont(100,"宋体",pDC);
screenx =pDC->GetDeviceCaps(LOGPIXELSX);//获取窗口每英寸像素数
screeny =pDC->GetDeviceCaps(LOGPIXELSY);
CExamle1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
DrawReport(pDC,FALSE);
m_titlefont.DeleteObject();
m_bodyfont.DeleteObject();
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CExamle1View printing
BOOL CExamle1View::OnPreparePrinting(CPrintInfo* pInfo)
{
pInfo->SetMaxPage(10);
BOOL ret = DoPreparePrinting(pInfo);
return ret;
}
void CExamle1View::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
printx =pDC->GetDeviceCaps(LOGPIXELSX);
printy =pDC->GetDeviceCaps(LOGPIXELSY);
xrate = (double)printx /screenx; //确定打印机与屏幕的比率
yrate = (double)printy /screeny;
}
void CExamle1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CExamle1View diagnostics
#ifdef _DEBUG
void CExamle1View::AssertValid() const
{
CView::AssertValid();
}
void CExamle1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CExamle1Doc* CExamle1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExamle1Doc)));
return (CExamle1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExamle1View message handlers
void CExamle1View::DrawReport(CDC *pDC, BOOL isPrinted,CPrintInfo* pInfo)
{
if (! isPrinted)
{
pDC->SelectObject(&m_titlefont);
pDC->TextOut(300,50,"人事信息报表");
pDC->SelectObject(&m_bodyfont);
}
else
{
pDC->SelectObject(&m_titlefont);
pDC->TextOut(300,50,"人事信息报表");
pDC->SelectObject(&m_bodyfont);
pInfo->m_bContinuePrinting =false;
if (pInfo->m_nCurPage ==2)
pDC->TextOut(100,10,"");
}
}
void CExamle1View::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
// pInfo->m_nCurPage = 2;
DrawReport(pDC,true,pInfo);
// CView::OnPrint(pDC, pInfo);
}
void CExamle1View::OnFilePrintPreview()
{
CPrintPreviewState* pState = new CPrintPreviewState;
if (!DoPrintPreview(IDD_PREVIEW, this,RUNTIME_CLASS(CPreView), pState))
{
TRACE0("Error: DoPrintPreview failed.\n");
AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
delete pState;
}
}
void CExamle1View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrepareDC(pDC, pInfo);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -