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

📄 createfontview.cpp

📁 通过选择可执行文件中菜单“字体”
💻 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
	ON_COMMAND_RANGE(ID_FONT_METHOD1,ID_FONT_METHOD4, OnFontStyle)
	ON_UPDATE_COMMAND_UI_RANGE(ID_FONT_METHOD1,ID_FONT_METHOD4, OnUpdateFontStyle)

	// 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
	m_nFontStyle = 0 ;
}

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);

	//设置LOGFONT结构,以便选择字体;
	static LOGFONT lf;
	lf.lfHeight=40;
	lf.lfWidth=20;
	lf.lfItalic=true;
	lf.lfUnderline=true;
	lf.lfStrikeOut=true;
	lf.lfOrientation=0;
	lf.lfWeight=800;
	lf.lfEscapement=0;
	lf.lfCharSet=GB2312_CHARSET;
	lf.lfPitchAndFamily=DEFAULT_PITCH|FF_SWISS;

//使用CreateFontIndirect创建字体;
	if(m_nFontStyle == 0)
	{
		CFont NewFont1;
		NewFont1.CreateFontIndirect(&lf);
		pDC->SetTextColor((COLORREF) 0x000FF0000) ;
		CFont* pOldFont1=pDC->SelectObject(&NewFont1);
		pDC->TextOut(0,10,"使用函数CreateFontIndirect创建字体");
		pDC->SelectObject(pOldFont1);
	}
//使用CreateFont创建字体;
	if(m_nFontStyle == 1)
	{
		CFont NewFont2;
		NewFont2.CreateFont(50,0,
							100,0,800,
							FALSE,FALSE,
							0,
							ANSI_CHARSET,
							OUT_DEFAULT_PRECIS,
							CLIP_DEFAULT_PRECIS,
							DEFAULT_QUALITY,
							DEFAULT_PITCH|FF_SWISS,
							"Arial");
		CFont* pOldFont2=pDC->SelectObject(&NewFont2);
		pDC->TextOut(0,200,"使用函数CreateFont创建字体") ;
		pDC->SelectObject(pOldFont2) ;
	}
//使用CreatePointFontIndirect创建字体;
	//该属性值的十分之一为度量单位;
	if(m_nFontStyle == 2) 
	{
		lf.lfHeight=250;
		
		CFont NewFont3 ;
		NewFont3.CreatePointFontIndirect(&lf,pDC) ;
		CFont* pOldFont3=pDC->SelectObject(&NewFont3) ;
		pDC->TextOut(0,350,"使用CreatePointFontIndirect创建字体") ;
		pDC->SelectObject(pOldFont3) ;
	}
//使用CreatePointFont创建字体;
	if(m_nFontStyle == 3)
	{
		CFont NewFont4 ;
		NewFont4.CreatePointFont(200,"Arial",pDC) ;
		CFont* pOldFont4=pDC->SelectObject(&NewFont4) ;
		pDC->TextOut(0,400,"使用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
void CCreateFontView::OnFontStyle(UINT nID) 
{
	// TODO: Add your command handler code here
	switch(nID)
	{
	case ID_FONT_METHOD1:
		m_nFontStyle = 0 ;
		break;
	case ID_FONT_METHOD2:
		m_nFontStyle = 1 ;
		break;
	case ID_FONT_METHOD3:
		m_nFontStyle = 2 ;
		break;
	case ID_FONT_METHOD4:
		m_nFontStyle = 3 ;
		break;
	default:;
	}
	Invalidate(TRUE) ;
}

void CCreateFontView::OnUpdateFontStyle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	int nFlag = 0 ;
	switch(pCmdUI->m_nID)
	{
	case ID_FONT_METHOD1:
		if(m_nFontStyle == 0)
			nFlag = 1 ;
		break;
	case ID_FONT_METHOD2:
		if(m_nFontStyle == 1)
			nFlag = 1 ;
		break;
	case ID_FONT_METHOD3:
		if(m_nFontStyle == 2)
			nFlag = 1 ;
		break;
	case ID_FONT_METHOD4:
		if(m_nFontStyle == 3)
			nFlag = 1 ;
	default:;
	}
	pCmdUI->SetCheck(nFlag) ;
}

⌨️ 快捷键说明

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