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

📄 fontdlgview.cpp

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

#include "stdafx.h"
#include "FontDlg.h"

#include "FontDlgDoc.h"
#include "FontDlgView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFontDlgView

IMPLEMENT_DYNCREATE(CFontDlgView, CView)

BEGIN_MESSAGE_MAP(CFontDlgView, CView)
	//{{AFX_MSG_MAP(CFontDlgView)
	ON_COMMAND(ID_VIEW_FONT, OnViewFont)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFontDlgView construction/destruction

CFontDlgView::CFontDlgView()
{
	// TODO: add construction code here
	//m_clrText=RGB(0,0,0);
}

CFontDlgView::~CFontDlgView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CFontDlgView drawing

void CFontDlgView::OnDraw(CDC* pDC)
{
	CFontDlgDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CFont  *pfntOld=pDC->SelectObject(&m_fontDlg);  // 设置字体
	pDC->SetTextColor(m_clrText);					// 设置文本颜色
	pDC->TextOut(10,10,"使用公用字体对话框动态设置字体");
	pDC->SelectObject(pfntOld);
}

/////////////////////////////////////////////////////////////////////////////
// CFontDlgView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CFontDlgView message handlers

void CFontDlgView::OnViewFont() 
{
	// TODO: Add your command handler code here
	CFontDialog  dlgFont;
	if(dlgFont.DoModal()==IDOK)
	{
		m_fontDlg.DeleteObject();
		LOGFONT  LogFnt;
		dlgFont.GetCurrentFont(&LogFnt);     // 获得用户所选择的字体
		m_fontDlg.CreateFontIndirect(&LogFnt);     // 创建用户所选择的字体
		// 或m_fontDlg.CreateFontIndirect(dlgFont.m_cf.lpLogFont);
		m_clrText=dlgFont.m_cf.rgbColors;     // 获得用户所选择的颜色
		// 或m_clrText=dlgFont.GetColor();
		Invalidate();
	}
}

⌨️ 快捷键说明

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