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

📄 fontview.cpp

📁 本代码创建所需要的字体
💻 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);
	// TODO: add draw code for native data here
	CString outstr[5];
    outstr[1]="1.使用函数CreatPointFont()创建字体字";
    outstr[2]="2.使用函数CreatFontIndirect()创建倾斜、带下划线的黑体字";
    outstr[3]="3.使用函数CreateFont()创建带删除线的大号字";
    outstr[4]="4.使用库存字体对象创建ANSI标准的等宽字";
    CFont *OldFont,NewFont;
    LOGFONT MyFont={
        30,
        10,
        0,
        0,
        0,
        1,
        1,
        0,
        ANSI_CHARSET,
        OUT_DEFAULT_PRECIS,
        CLIP_DEFAULT_PRECIS,
        DEFAULT_QUALITY,
        DEFAULT_PITCH,
        "黑体"
    };
    pDC->TextOut(0,10,"创建字体的几种方法:");
    for(int i=1;i<5;i++){
        switch(i){
        case 1:
            //使用函数CreatPointFont()创建字体
            NewFont.CreatePointFont(200,"宋体",NULL);
            break;
        case 2:
            //使用函数CreateFontIndirect()创建字体
            NewFont.CreateFontIndirect(&MyFont);
            break;
        case 3:
            //使用函数CreateFont()创建字体
            NewFont.CreateFont(30,10,0,0,FW_HEAVY,false,false,
                               true,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
                               CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
                               DEFAULT_PITCH|FF_DONTCARE,"大号字");
            break;
        case 4:
            //使用库存字体对象创建字体
            pDC->SelectStockObject(ANSI_FIXED_FONT);
            break;
        }
        OldFont=pDC->SelectObject(&NewFont);
        pDC->TextOut(0,60*i,outstr[i]);
        pDC->SelectObject(OldFont);
        NewFont.DeleteObject();
    }

}

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

⌨️ 快捷键说明

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