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

📄 chapter09view.cpp

📁 精通MFC程序设计 第9章属性表与向导
💻 CPP
字号:
// Chapter09View.cpp : implementation of the CChapter09View class
//

#include "stdafx.h"
#include "Chapter09.h"

#include "Chapter09Doc.h"
#include "Chapter09View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChapter09View

IMPLEMENT_DYNCREATE(CChapter09View, CEditView)

BEGIN_MESSAGE_MAP(CChapter09View, CEditView)
	//{{AFX_MSG_MAP(CChapter09View)
	ON_COMMAND(ID_FONT_CFG, OnFontCfg)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
	ON_MESSAGE(WM_USER_APPLY, OnApply)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChapter09View construction/destruction

CChapter09View::CChapter09View():m_FontSheet("字体配置")
{
	// TODO: add construction code here

}

CChapter09View::~CChapter09View()
{
}

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

	BOOL bPreCreated = CEditView::PreCreateWindow(cs);
	cs.style &= ~(ES_AUTOHSCROLL|WS_HSCROLL);	// Enable word-wrapping

	return bPreCreated;
}

/////////////////////////////////////////////////////////////////////////////
// CChapter09View drawing

void CChapter09View::OnDraw(CDC* pDC)
{
	CChapter09Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CChapter09View printing

BOOL CChapter09View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default CEditView preparation
	return CEditView::OnPreparePrinting(pInfo);
}

void CChapter09View::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView begin printing.
	CEditView::OnBeginPrinting(pDC, pInfo);
}

void CChapter09View::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// Default CEditView end printing
	CEditView::OnEndPrinting(pDC, pInfo);
}

/////////////////////////////////////////////////////////////////////////////
// CChapter09View diagnostics

#ifdef _DEBUG
void CChapter09View::AssertValid() const
{
	CEditView::AssertValid();
}

void CChapter09View::Dump(CDumpContext& dc) const
{
	CEditView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CChapter09View message handlers

BOOL CChapter09View::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pNewFont)
		delete pNewFont;
	return CEditView::DestroyWindow();
}

void CChapter09View::OnFontCfg() 
{
	// TODO: Add your command handler code here
	m_FontSheet.SetText("我爱你");
	m_FontSheet.DoModal();
}

void CChapter09View::OnApply(WPARAM wParam, LPARAM lParam)
{
	//获取编辑视所包含的编辑控件
	CEdit& MessageBody=GetEditCtrl();
	CString str;
	//设置正文中的字体
	LOGFONT logft;
	//获取字体大小属性
	logft.lfHeight=m_FontSheet.m_Size.m_Height;
	logft.lfWidth=m_FontSheet.m_Size.m_Width;
	logft.lfEscapement=0;
	//获取效果
	logft.lfWeight=m_FontSheet.m_Effect.m_bBold?FW_BOLD:FW_NORMAL;
	logft.lfItalic=m_FontSheet.m_Effect.m_bItalic;//
	logft.lfUnderline =m_FontSheet.m_Effect.m_bUnderline;
	//设置为系统字体
	m_FontSheet.m_Font.m_lstFont.GetText(\
		m_FontSheet.m_Font.m_lstFont.GetCurSel(),str);
	logft.lfStrikeOut=FALSE;
	//解析字体和字符集
	strcpy(logft.lfFaceName,str.Left(str.Find("+")));
	logft.lfCharSet=atoi(str.Mid(str.Find("+")));
	//new出来的对象需要在适当时候手工删除,别忘记了
	pNewFont=new CFont();
	pNewFont->CreateFontIndirect(&logft);
	//设置编辑控件字体
	MessageBody.SetFont(pNewFont,FALSE);
}

⌨️ 快捷键说明

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