📄 createfontview.cpp
字号:
// CreateFontView.cpp : implementation of the CCreateFontView class
//
#include "stdafx.h"
#include "CreateFont.h"
#include "CreateFontDoc.h"
#include "CreateFontView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCreateFontView
IMPLEMENT_DYNCREATE(CCreateFontView, CView)
BEGIN_MESSAGE_MAP(CCreateFontView, CView)
//{{AFX_MSG_MAP(CCreateFontView)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CCreateFontView construction/destruction
CCreateFontView::CCreateFontView()
{
// TODO: add construction code here
}
CCreateFontView::~CCreateFontView()
{
}
BOOL CCreateFontView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCreateFontView drawing
void CCreateFontView::OnDraw(CDC* pDC)
{
CCreateFontDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
// 设置LOGFONT结构
LOGFONT lf;
lf.lfHeight = 40;
lf.lfWidth = 20;
lf.lfItalic = 1;
lf.lfUnderline = 1;
lf.lfStrikeOut = 0;
lf.lfOrientation = 0;
lf.lfWeight = 800;
lf.lfEscapement = 0;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfPitchAndFamily = DEFAULT_PITCH|FF_SWISS;
// 第一种方法:使用CreateFontIndirect创建字体
CFont myFont1;
myFont1.CreateFontIndirect(&lf);
pDC->SetTextColor(RGB(255,0,0)) ;
CFont* pOldFont1 = pDC->SelectObject(&myFont1);
pDC->TextOut(0,10,"调用函数CreateFontIndirect创建字体");
// 恢复字体对象
pDC->SelectObject(pOldFont1);
// 第二种方法:使用CreateFont创建字体;
CFont myFont2;
myFont2.CreateFont(50,0,
100,0,800,
FALSE,FALSE,
0,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_SWISS,
_T("Arial"));
pDC->SetTextColor(RGB(0,255,0));
pDC->SetBkColor(RGB(0,0,0));
CFont* pOldFont2 = pDC->SelectObject(&myFont2);
pDC->TextOut(0,200,_T("调用函数CreateFont创建字体"));
// 恢复字体对象
pDC->SelectObject(pOldFont2);
// 第三种方法:使用CreatePointFontIndirect创建字体;
lf.lfHeight = 260;
lf.lfItalic = 0;
lf.lfStrikeOut = 1;
CFont myFont3 ;
myFont3.CreatePointFontIndirect(&lf,pDC);
CFont* pOldFont3 = pDC->SelectObject(&myFont3);
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(255,255,0));
pDC->TextOut(20,300,_T("调用CreatePointFontIndirect创建字体"));
// 恢复字体对象
pDC->SelectObject(pOldFont3);
// 第四种方法: 使用CreatePointFont创建字体;
CFont myFont4;
myFont4.CreatePointFont(200,_T("Arial"),pDC);
pDC->SetTextColor(RGB(255,0,255));
pDC->SetBkColor(RGB(0,255,0));
CFont* pOldFont4 = pDC->SelectObject(&myFont4) ;
pDC->TextOut(200,370,_T("调用CreatePointFont创建字体"));
// 恢复字体对象
pDC->SelectObject(pOldFont4);
}
/////////////////////////////////////////////////////////////////////////////
// CCreateFontView printing
BOOL CCreateFontView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCreateFontView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCreateFontView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCreateFontView diagnostics
#ifdef _DEBUG
void CCreateFontView::AssertValid() const
{
CView::AssertValid();
}
void CCreateFontView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCreateFontDoc* CCreateFontView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCreateFontDoc)));
return (CCreateFontDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCreateFontView message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -