📄 ch9demo5view.cpp
字号:
// Ch9Demo5View.cpp : implementation of the CCh9Demo5View class
//
#include "stdafx.h"
#include "Ch9Demo5.h"
#include "Ch9Demo5Doc.h"
#include "Ch9Demo5View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo5View
IMPLEMENT_DYNCREATE(CCh9Demo5View, CView)
BEGIN_MESSAGE_MAP(CCh9Demo5View, CView)
//{{AFX_MSG_MAP(CCh9Demo5View)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo5View construction/destruction
CCh9Demo5View::CCh9Demo5View()
{
// TODO: add construction code here
}
CCh9Demo5View::~CCh9Demo5View()
{
}
BOOL CCh9Demo5View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo5View drawing
void CCh9Demo5View::OnDraw(CDC* pDC)
{
CCh9Demo5Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CFont myfont,*oldfont;
LOGFONT font;
memset(&font,0,sizeof(LOGFONT)); //为字体结构赋初值,默认值
font.lfHeight=50; //字体高度为50
font.lfWeight=600;
font.lfItalic=TRUE; //采用斜体
strcpy(font.lfFaceName,"Times New Roman"); //字符集
font.lfEscapement=-100; //字体向下倾斜10度
myfont.CreateFontIndirect(&font); //创建新字体
oldfont=pDC->SelectObject(&myfont); //将新字体选入设备环境
pDC->SetTextColor(RGB(200,10,10)); //文本颜色
pDC->SetBkMode(TRANSPARENT); //文本采用透明背景色
pDC->TextOut(10,20,"使用CFont对象创建的字体!"); //用新字体输出"新字体"字符串
TEXTMETRIC tm; //定义TEXTMETRIC结构tm
pDC->GetTextMetrics(&tm); //获取字体信息
CString str1,str2,str3;
str1.Format("字体高度为:%d",tm.tmHeight);
str2.Format("字体的平均字符宽度为:%d",tm.tmAveCharWidth);
pDC->SelectObject(oldfont); //恢复设备环境中的旧字体
pDC->SetTextColor(RGB(0,0,128)); //设定输出的文本所用的颜色
pDC->TextOut(10,100,str1); //用系统默认字体输出str1字符串
pDC->TextOut(10,120,str2); //用系统默认字体输出str2字符串
}
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo5View printing
BOOL CCh9Demo5View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCh9Demo5View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCh9Demo5View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo5View diagnostics
#ifdef _DEBUG
void CCh9Demo5View::AssertValid() const
{
CView::AssertValid();
}
void CCh9Demo5View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCh9Demo5Doc* CCh9Demo5View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCh9Demo5Doc)));
return (CCh9Demo5Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo5View message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -