📄 testfontview.cpp
字号:
// TestFontView.cpp : implementation of the CTestFontView class
//
#include "stdafx.h"
#include "TestFont.h"
#include "TestFontDoc.h"
#include "TestFontView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestFontView
IMPLEMENT_DYNCREATE(CTestFontView, CView)
BEGIN_MESSAGE_MAP(CTestFontView, CView)
//{{AFX_MSG_MAP(CTestFontView)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CTestFontView construction/destruction
CTestFontView::CTestFontView()
{
// TODO: add construction code here
}
CTestFontView::~CTestFontView()
{
}
BOOL CTestFontView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTestFontView drawing
#include "math.h"
void CTestFontView::OnDraw(CDC* pDC)
{
CTestFontDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
for(int i=0;i<7;i++)
{
//第一步:创建字体
CFont NewFont;
//调用CreateFont成员函数实际创建字体
NewFont.CreateFont(30-i,
0,
300*i,
0,
400,
FALSE,FALSE,0,
DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH&FF_SWISS,
"Arial");
//第二步:将新的字体选入设备环境,并保存旧字体
CFont * pOldFont=(CFont *)pDC->SelectObject(&NewFont);
//用TextOut输出文本
pDC->TextOut(100*cos(3.1415926/6.0*i)+300,
-100*sin(3.1415926/6.0*i)+300,
"使用CFont对象");
//第三步:恢复设备环境中的旧字体
pDC->SelectObject(pOldFont);
}
}
/////////////////////////////////////////////////////////////////////////////
// CTestFontView printing
BOOL CTestFontView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTestFontView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTestFontView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTestFontView diagnostics
#ifdef _DEBUG
void CTestFontView::AssertValid() const
{
CView::AssertValid();
}
void CTestFontView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTestFontDoc* CTestFontView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestFontDoc)));
return (CTestFontDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestFontView message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -