【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,FontView.cpp,希望对大家有所帮助!
// FontView.cpp : implementation of the CFontView class
//
#include "stdafx.h"
#include "Font.h"
#include "FontDoc.h"
#include "FontView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFontView
IMPLEMENT_DYNCREATE(CFontView, CView)
BEGIN_MESSAGE_MAP(CFontView, CView)
//{{AFX_MSG_MAP(CFontView)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CFontView construction/destruction
CFontView::CFontView()
{
// TODO: add construction code here
}
CFontView::~CFontView()
{
}
BOOL CFontView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CFontView drawing
void CFontView::OnDraw(CDC* pDC)
{
CFontDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
TEXTMETRIC tm;
int y=10;
CFont font,*pfontOld;
pfontOld=(CFont *)pDC->SelectStockObject(DEVICE_DEFAULT_FONT);
pDC->TextOut(10,y,"This is Device Default Font.");
pDC->GetTextMetrics(&tm);
y=y+tm.tmHeight+tm.tmExternalLeading;
font.CreatePointFont(200,"Time New Roman",pDC);
pfontOld=pDC->SelectObject(&font);
pDC->SetTextColor(RGB(0,0,255));
pDC->TextOut(10,y,"This is 20pt Time New Roman Font.");
pDC->GetTextMetrics(&tm);
y=y+tm.tmHeight+tm.tmExternalLeading;
font.DeleteObject();
LOGFONT LogFont={
30,
24,
0,0,
FW_HEAVY,
1,1,0,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH,
"Arial"
};
font.CreateFontIndirect(&LogFont);
pDC->SelectObject(&font);
pDC->SetTextColor(RGB(255,0,0));
pDC->TextOut(10,y,"Hello! This is LOGFONT Font.");
pDC->GetTextMetrics(&tm);
y=y+tm.tmHeight+tm.tmExternalLeading;
font.DeleteObject();
font.CreateFont(35,0,0,0,FW_BOLD,0,0,0,0,0,0,0,0,"Courier");
pDC->SelectObject(&font);
pDC->SetTextColor(RGB(0,255,0));
pDC->DrawText("Hello!This is LOGFONT Font,\n Use CreateFont().",
CRect(10,y,600,y+100),DT_LEFT);
font.DeleteObject();
pDC->SelectObject(pfontOld);
}
/////////////////////////////////////////////////////////////////////////////
// CFontView printing
BOOL CFontView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CFontView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CFontView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CFontView diagnostics
#ifdef _DEBUG
void CFontView::AssertValid() const
{
CView::AssertValid();
}
void CFontView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CFontDoc* CFontView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFontDoc)));
return (CFontDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFontView message handlers