📄 testfontview.cpp
字号:
// TestFontView.cpp : implementation of the CTestFontView class
//
#include "stdafx.h"
#include "TestFont.h"
#include "math.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
void CTestFontView::OnDraw(CDC* pDC)
{
CTestFontDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int i;
CRect rect;
GetClientRect(&rect);
CBrush* pOldBrush=(CBrush *)pDC->SelectStockObject(WHITE_BRUSH);
pDC->Rectangle(rect);
pDC->SelectObject(pOldBrush);
pDC->SetViewportOrg(500,300);
pDC->SetTextAlign(TA_CENTER);
for(i=0;i<3;i++)
{
WriteText(pDC,0,30*i-50,16+4*i,0);
}
pDC->SetTextAlign(TA_LEFT);
for(i=0;i<12;i++)
{
WriteText(pDC,100*cos(3.1415926/6.0*i),
-100*sin(3.1415926/6.0*i),24,300*i);
}
return ;
}
/////////////////////////////////////////////////////////////////////////////
// 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
void CTestFontView::WriteText(CDC *pDC, int nX, int nY, int nSize, int nAngle)
{
CFont* pOldFont;
CFont* pNewFont=new CFont;
pNewFont->CreateFont(nSize,0,nAngle,0,
900,FALSE,FALSE,0,
ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH&FF_SWISS,
"Aerial");
pOldFont=(CFont *)pDC->SelectObject(pNewFont);
pDC->TextOut(nX,nY,"我爱MFC编程!");
pDC->SelectObject(pOldFont);
delete pNewFont;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -