notepadview.cpp
来自「深入浅出Visual C++入门进阶与应用实例 随书光盘 作者 何志丹」· C++ 代码 · 共 127 行
CPP
127 行
// NotePadView.cpp : implementation of the CNotePadView class
//
#include "stdafx.h"
#include "NotePad.h"
#include "NotePadDoc.h"
#include "NotePadView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNotePadView
IMPLEMENT_DYNCREATE(CNotePadView, CEditView)
BEGIN_MESSAGE_MAP(CNotePadView, CEditView)
//{{AFX_MSG_MAP(CNotePadView)
ON_COMMAND(ID_SET_FONT, OnSetFont)
//}}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)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNotePadView construction/destruction
CNotePadView::CNotePadView()
{
// TODO: add construction code here
}
CNotePadView::~CNotePadView()
{
}
BOOL CNotePadView::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;
}
/////////////////////////////////////////////////////////////////////////////
// CNotePadView drawing
void CNotePadView::OnDraw(CDC* pDC)
{
CNotePadDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CNotePadView printing
BOOL CNotePadView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default CEditView preparation
return CEditView::OnPreparePrinting(pInfo);
}
void CNotePadView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView begin printing.
CEditView::OnBeginPrinting(pDC, pInfo);
}
void CNotePadView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView end printing
CEditView::OnEndPrinting(pDC, pInfo);
}
/////////////////////////////////////////////////////////////////////////////
// CNotePadView diagnostics
#ifdef _DEBUG
void CNotePadView::AssertValid() const
{
CEditView::AssertValid();
}
void CNotePadView::Dump(CDumpContext& dc) const
{
CEditView::Dump(dc);
}
CNotePadDoc* CNotePadView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNotePadDoc)));
return (CNotePadDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CNotePadView message handlers
void CNotePadView::OnSetFont()
{
CFontDialog dlg(NULL,CF_SCREENFONTS) ;
if(IDOK == dlg.DoModal())//用户点击了确定按钮
{
LOGFONT lf;
dlg.GetCurrentFont(&lf) ;
//删除旧资源以减少异常
static CFont font ; //不能定义成局部变量,必须是全局变量或类成员或静态变量
font.DeleteObject();
font.CreatePointFontIndirect(&lf);
CEdit& edit = GetEditCtrl();//取得编辑框
edit.SetFont(&font);//设置字体
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?