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

📄 fontview.cpp

📁 文件包含了很多VC实例
💻 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);
	int nPosition = 0 ;
	for(int i = 7 ; i <= 28 ; i+= 2 )
	{
		Show(pDC,nPosition,i);
	}
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// 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

void CFontView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	pDC->SetMapMode(MM_ANISOTROPIC);
	pDC->SetWindowExt(1440,1440);
	pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),
		-pDC->GetDeviceCaps(LOGPIXELSY));
	CView::OnPrepareDC(pDC, pInfo);
}

void CFontView::Show(CDC* pDC , int& nPos , int nPoints)
{
	TEXTMETRIC tm ;
	CFont fontText ;
	CString strText;
	CSize sizeText;
	fontText.CreateFont(nPoints*20,0,0,0,400,FALSE,FALSE,0,
		ANSI_CHARSET,OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
		DEFAULT_PITCH|FF_SWISS,"Times New Roman");
	CFont* pOldFont = (CFont*)pDC->SelectObject(&fontText);
	pDC->GetTextMetrics(&tm);
	strText.Format("This %d -points with \"Times New Roman\" ",nPoints);
	sizeText = pDC->GetTextExtent(strText);
	pDC->TextOut(0,nPos,strText);
	pDC->SelectObject(pOldFont);
	nPos -= tm.tmHeight + tm.tmExternalLeading ; 
}

⌨️ 快捷键说明

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