www.pudn.com > vc++Notepad.rar > NotepadView.cpp


// 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_FORMAT_FONT, OnFormatFont) 
	ON_COMMAND(ID_FORMAT_RETURN, OnFormatReturn) 
	ON_UPDATE_COMMAND_UI(ID_FORMAT_RETURN, OnUpdateFormatReturn) 
	//}}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::OnFormatFont()  
{ 
	// TODO: Add your command handler code here 
	//字体修改实现; 
	LOGFONT lf; 
	CFont *font=this->GetEditCtrl().GetFont(); //GET当前字体; 
	if(font==NULL)	//if当前无字体,创建默认的字体; 
	{ 
		font =new CFont; 
		font->CreatePointFont(120,"Fixedsys"); 
		font->GetLogFont(&lf); 
		delete font; 
	} 
	else 
	{ 
		font->GetLogFont(&lf); 
	} 
	CFontDialog cf(&lf); 
	if(cf.DoModal()==IDOK) 
	{ 
		this->m_Font.DeleteObject(); 
 
		this->m_Font.CreateFontIndirect(&lf); 
		this->SetFont(&this->m_Font); 
	} 
} 
 
void CNotepadView::OnFormatReturn()  
{ 
	// TODO: Add your command handler code here 
	//自动换行实现 
	bChk=!bChk; 
	if(!bChk) 
	{ 
		ShowScrollBar(SB_HORZ,true); 
	} 
	else 
	{ 
		ShowScrollBar(SB_HORZ,false); 
	} 
} 
 
void CNotepadView::OnUpdateFormatReturn(CCmdUI* pCmdUI)   //update UI handler 
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->SetCheck(bChk); 
}