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

📄 ex05bview.cpp

📁 一个有效展示True Type字体的例子
💻 CPP
字号:
// EX05BView.cpp : implementation of the CEX05BView class
//

#include "stdafx.h"
#include "EX05B.h"

#include "EX05BDoc.h"
#include "EX05BView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEX05BView

IMPLEMENT_DYNCREATE(CEX05BView, CView)

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

/////////////////////////////////////////////////////////////////////////////
// CEX05BView construction/destruction

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

}

CEX05BView::~CEX05BView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEX05BView drawing

void CEX05BView::OnDraw(CDC* pDC)
{
	// TODO: add draw code for native data here
	CFont fontTest1, fontTest2, fontTest3, fontTest4;
	fontTest1.CreateFont( 50, 0, 0, 0, 400, FALSE, FALSE, 0, 
						 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
						 DEFAULT_QUALITY, DEFAULT_PITCH|FF_SWISS, "Arial" );
	CFont *pOldFont = ( CFont * )pDC->SelectObject( &fontTest1 );
	TraceMetrics( pDC );
	pDC->TextOut( 0, 0, "This is Arial, default width" );

	fontTest2.CreateFont( 50, 0, 0, 0, 400, FALSE, FALSE, 0, 
						 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
						 DEFAULT_QUALITY, DEFAULT_PITCH|FF_MODERN, "Courier" );
	pDC->SelectObject( &fontTest2 );
	TraceMetrics( pDC );
	pDC->TextOut( 0, 100, "This is Courier, default width" );

	fontTest3.CreateFont( 50, 0, 0, 0, 400, FALSE, FALSE, 0, 
						 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
						 DEFAULT_QUALITY, DEFAULT_PITCH|FF_ROMAN, NULL );
	pDC->SelectObject( &fontTest3 );
	TraceMetrics( pDC );
	pDC->TextOut( 0, 200, "This is generic Roman, variable width" );

	fontTest4.CreateFont( 50, 0, 0, 0, 400, FALSE, FALSE, 0, 
						 ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
						 DEFAULT_QUALITY, DEFAULT_PITCH|FF_MODERN, "LinePrinter" );
	pDC->SelectObject( &fontTest4 );
	TraceMetrics( pDC );
	pDC->TextOut( 0, 300, "This is LinePrinter, default width" );
	
	pDC->SelectObject( pOldFont );

}

/////////////////////////////////////////////////////////////////////////////
// CEX05BView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CEX05BView message handlers

void CEX05BView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	CRect clientRect;
	GetClientRect( clientRect );
	pDC->SetMapMode( MM_ANISOTROPIC );
	pDC->SetWindowExt( 400, 450 );
	pDC->SetViewportExt( clientRect.right, clientRect.bottom );
	pDC->SetViewportOrg( 0, 0 );
}

void CEX05BView::TraceMetrics( CDC *pDC ){
	TEXTMETRIC tm;
	char szFaceName[100];
	pDC->GetTextMetrics( &tm );
	pDC->GetTextFace( 99, szFaceName );
	TRACE( "font = %s, tmHeight = %d, tmInternalLeading = %d,"
			"tmExternalLeading = %d\n", szFaceName, tm.tmHeight,
			tm.tmInternalLeading, tm.tmExternalLeading );
}

⌨️ 快捷键说明

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