📄 notepadeview.cpp
字号:
// NotepadeView.cpp : implementation of the CNotepadeView class
//
#include "stdafx.h"
#include "Notepade.h"
#include "NotepadeDoc.h"
#include "NotepadeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNotepadeView
//CFont CNotepadeView::m_Font;
IMPLEMENT_DYNCREATE(CNotepadeView, CEditView)
BEGIN_MESSAGE_MAP(CNotepadeView, CEditView)
//{{AFX_MSG_MAP(CNotepadeView)
ON_WM_CREATE()
ON_UPDATE_COMMAND_UI(ID_FORMAT_RETURN, OnUpdateFormatReturn)
ON_COMMAND(ID_FORMAT_FONT, OnFormatFont)
ON_COMMAND(ID_FORMAT_RETURN, OnFormatReturn)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CNotepadeView construction/destruction
CNotepadeView::CNotepadeView()
{
// TODO: add construction code here
bChk=true;
}
CNotepadeView::~CNotepadeView()
{
}
BOOL CNotepadeView::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;
}
/////////////////////////////////////////////////////////////////////////////
// CNotepadeView drawing
void CNotepadeView::OnDraw(CDC* pDC)
{
CNotepadeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CNotepadeView printing
BOOL CNotepadeView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default CEditView preparation
return CEditView::OnPreparePrinting(pInfo);
}
void CNotepadeView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView begin printing.
CEditView::OnBeginPrinting(pDC, pInfo);
}
void CNotepadeView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView end printing
CEditView::OnEndPrinting(pDC, pInfo);
}
/////////////////////////////////////////////////////////////////////////////
// CNotepadeView diagnostics
#ifdef _DEBUG
void CNotepadeView::AssertValid() const
{
CEditView::AssertValid();
}
void CNotepadeView::Dump(CDumpContext& dc) const
{
CEditView::Dump(dc);
}
CNotepadeDoc* CNotepadeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CNotepadeDoc)));
return (CNotepadeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CNotepadeView message handlers
int CNotepadeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEditView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CEdit& edit = GetEditCtrl();
if (m_Font.m_hObject == NULL)
{
m_Font.CreatePointFont(120,"Fixedsys");
}
if (m_Font.m_hObject != NULL)
edit.SetFont (&m_Font);
edit.SetTabStops (16);
return 0;
}
void CNotepadeView::OnUpdateFormatReturn(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(bChk);
}
void CNotepadeView::OnFormatFont()
{
// TODO: Add your command handler code here
LOGFONT lf; //设置打开字体对话框的默认字体
CFont *font=this->GetEditCtrl().GetFont();//得到当前视图字体
if(font==NULL) //当前无字体,创建默认的字体
{
font =new CFont;
font->CreatePointFont(120,"Fixedsys");
font->GetLogFont(&lf); //初始化LOGFONT
delete font;
}
else
{
font->GetLogFont(&lf); //初始化LOGFONT
}
CFontDialog cf(&lf);
if(cf.DoModal()==IDOK)
{
this->m_Font.DeleteObject();
this->m_Font.CreateFontIndirect(&lf);
this->SetFont(&this->m_Font);
}
}
void CNotepadeView::OnFormatReturn()
{
// TODO: Add your command handler code here
bChk=!bChk;
if(!bChk)
{
ShowScrollBar(SB_HORZ,true);
}
else
{
ShowScrollBar(SB_HORZ,false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -