【VC开源代码栏目提醒】:网学会员,鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“CFont_1View.cpp”一文,供大家参考学习!
// CFont_1View.cpp : implementation of the CCFont_1View class
//
#include "stdafx.h"
#include "CFont_1.h"
#include "CFont_1Doc.h"
#include "CFont_1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCFont_1View
IMPLEMENT_DYNCREATE(CCFont_1View, CView)
BEGIN_MESSAGE_MAP(CCFont_1View, CView)
//{{AFX_MSG_MAP(CCFont_1View)
ON_COMMAND(IDM_FONT, OnFont)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CCFont_1View construction/destruction
CCFont_1View::CCFont_1View()
{
// TODO: add construction code here
strName="";
}
CCFont_1View::~CCFont_1View()
{
}
BOOL CCFont_1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCFont_1View drawing
void CCFont_1View::OnDraw(CDC* pDC)
{
CCFont_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CFont *pOldFont=pDC->SelectObject(&m_font); //设备环境中添加新的字体
pDC->TextOut(0,0,strName); //输出字体
pDC->SelectObject(pOldFont); //还原旧的字体
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCFont_1View printing
BOOL CCFont_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCFont_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCFont_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCFont_1View diagnostics
#ifdef _DEBUG
void CCFont_1View::AssertValid() const
{
CView::AssertValid();
}
void CCFont_1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCFont_1Doc* CCFont_1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCFont_1Doc)));
return (CCFont_1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCFont_1View message handlers
void CCFont_1View::OnFont()
{
// TODO: Add your command handler code here
CFontDialog dlg;
if(IDOK==dlg.DoModal()) //打开字体对话框
{
if(m_font.m_hObject) //若CFont对象已经创建
m_font.DeleteObject();
m_font.CreateFontIndirect(dlg.m_cf.lpLogFont);
//创建CFont对象
strName=dlg.m_cf.lpLogFont->lfFaceName;
Invalidate(); //使窗口无效
}
}