📄 exam5_2view.cpp
字号:
// Exam5_2View.cpp : implementation of the CExam5_2View class
//
#include "stdafx.h"
#include "Exam5_2.h"
#include "Exam5_2Doc.h"
#include "Exam5_2View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExam5_2View
IMPLEMENT_DYNCREATE(CExam5_2View, CView)
BEGIN_MESSAGE_MAP(CExam5_2View, CView)
//{{AFX_MSG_MAP(CExam5_2View)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CExam5_2View construction/destruction
CExam5_2View::CExam5_2View()
{
// TODO: add construction code here
}
CExam5_2View::~CExam5_2View()
{
}
BOOL CExam5_2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CExam5_2View drawing
void CExam5_2View::OnDraw(CDC* pDC)
{
CExam5_2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int y; int x;
CString outstr[4];
outstr[0]="第一个紫红色的使用系统字体的文本串";
outstr[1]="第二个黄色黑体文本串";
outstr[2]="第三个蓝色文本串";
outstr[3]="最后一个大号字,加下划线的斜体文本串";
x=0;y=0;
//输出第一行
pDC->SetTextColor (RGB(255,0,255));
pDC->TextOut (x,y,outstr[0]);
//输出第二行
TEXTMETRIC tm;
pDC->GetTextMetrics (&tm);
y=y+tm.tmHeight+100*tm.tmExternalLeading ;
CFont NewFont1;
NewFont1.CreateFont (30,10,0,0, FW_HEAVY, false,false,false,ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,"黑体");
CFont *pOldFont;
pOldFont=pDC->SelectObject (&NewFont1);
pDC->SetTextColor(RGB(255,255,0));
pDC->TextOut(x,y,outstr[1]);
//输出第三个文本串
pDC->GetTextMetrics (&tm);
pDC->SetTextColor (RGB(0,0,255));
CSize strSize=pDC->GetTextExtent (outstr[1],outstr[1].GetLength ());
x+=strSize.cx;
pDC->TextOut (x,y,outstr[2]);
// 输出第四个文本串
pDC->GetTextMetrics (&tm);
x=0;
y=y+tm.tmHeight+20*tm.tmExternalLeading ;
CFont NewFont2;
NewFont2.CreateFont (30,0,0,0,FW_NORMAL, true,true,false,ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE, "大号字");
pDC->SelectObject (&NewFont2);
pDC->SetTextColor(RGB(155,155,155));
pDC->TextOut(x,y,outstr[3]);
pDC->SelectObject (pOldFont);
pDC->SelectObject (&NewFont2);
pDC->SetTextColor(RGB(155,155,155));
pDC->TextOut(x,y,outstr[3]);
pDC->SelectObject (pOldFont);
}
/////////////////////////////////////////////////////////////////////////////
// CExam5_2View printing
BOOL CExam5_2View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CExam5_2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CExam5_2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CExam5_2View diagnostics
#ifdef _DEBUG
void CExam5_2View::AssertValid() const
{
CView::AssertValid();
}
void CExam5_2View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CExam5_2Doc* CExam5_2View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExam5_2Doc)));
return (CExam5_2Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExam5_2View message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -