⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usefontview.cpp

📁 这个是我们学校用的VC++教案
💻 CPP
字号:
// UseFontView.cpp : implementation of the CUseFontView class
//

#include "stdafx.h"
#include "UseFont.h"

#include "UseFontDoc.h"
#include "UseFontView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CUseFontView

IMPLEMENT_DYNCREATE(CUseFontView, CView)

BEGIN_MESSAGE_MAP(CUseFontView, CView)
	//{{AFX_MSG_MAP(CUseFontView)
		// 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
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUseFontView construction/destruction

CUseFontView::CUseFontView()
{
	// TODO: add construction code here

}

CUseFontView::~CUseFontView()
{
}

BOOL CUseFontView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CUseFontView drawing

void CUseFontView::OnDraw(CDC* pDC)
{
	CUseFontDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	TEXTMETRIC  tm;		// 字体信息结构
	int  y=10;			// 输出文本的Y坐标
	CFont  fntZdy, *pfntOld;
	pfntOld=(CFont*)pDC->SelectStockObject(DEVICE_DEFAULT_FONT);  // 选择堆字体
	pDC->TextOut(10, y, "Hello! This is Device Default Font.");
	pDC->GetTextMetrics(&tm);   // 获取字体信息tm
	y=y+tm.tmHeight+tm.tmExternalLeading;
	fntZdy.CreatePointFont(200, "Time New Roman", pDC);   // 创建Time New Roman字体,高度为20像素
	pfntOld=pDC->SelectObject(&fntZdy);		// 选入设备环境
	pDC->SetTextColor(RGB(0, 0, 255));		// 设置文本颜色为蓝色
	pDC->TextOut(10, y, "Hello! This is 20 Pt Time New Roman Font.");
	pDC->GetTextMetrics(&tm); 
	y=y+tm.tmHeight+tm.tmExternalLeading;
	fntZdy.DeleteObject();		// 删除创建的字体
	LOGFONT  LogFnt={		// 定义新的字体  
		30,					// 字体高度为30像素
		24,					// 字体宽度为24像素
		0,0,				// 文本不倾斜
		FW_HEAVY,			// 字体的粗细度,FW_HEAVY为最粗
		1,					// 字体为斜体
		1,					// 输出时带下划线
		0,					// 无删除线
		ANSI_CHARSET,		// 所用字符集为ANSI_CHARSET
		OUT_DEFAULT_PRECIS,	// 输出精度为默认精度
		CLIP_DEFAULT_PRECIS,// 裁剪精度为默认精度
		DEFAULT_QUALITY,	// 输出质量为默认值
		DEFAULT_PITCH,		// 字间距使用默认值
		"Arial"				// 匹配的字体
	};
	fntZdy.CreateFontIndirect(&LogFnt);   // 创建字体
	pDC->SelectObject(&fntZdy);
	pDC->SetTextColor(RGB(255, 0, 0));    // 设置文本颜色为红色
	pDC->TextOut(10, y, "Hello! This is LOGFONT Font.");
	pDC->GetTextMetrics(&tm); 
	y=y+tm.tmHeight+tm.tmExternalLeading;
	fntZdy.DeleteObject();
	fntZdy.CreateFont(35,0,0,0,FW_BOLD,0,0,0,0,0,0,0,0,"Courier");	// 创建字体
	pDC->SelectObject(&fntZdy);
	pDC->SetTextColor(RGB(0, 255, 0));    // 设置文本颜色为绿色
	pDC->DrawText("Hello! This is LOGFONT Font,\nUse CreateFont().",CRect(10,y,600,y+100),DT_LEFT);
	fntZdy.DeleteObject();
	pDC->SelectObject(pfntOld);		// 恢复系统原来字体
}

/////////////////////////////////////////////////////////////////////////////
// CUseFontView diagnostics

#ifdef _DEBUG
void CUseFontView::AssertValid() const
{
	CView::AssertValid();
}

void CUseFontView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CUseFontDoc* CUseFontView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CUseFontDoc)));
	return (CUseFontDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CUseFontView message handlers

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -