exeditview.cpp

来自「文件包含了很多VC实例」· C++ 代码 · 共 166 行

CPP
166
字号
// ExEditView.cpp : implementation of the CExEditView class
//

#include "stdafx.h"
#include "ExEdit.h"

#include "ExEditDoc.h"
#include "ExEditView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CExEditView

IMPLEMENT_DYNCREATE(CExEditView, CView)

BEGIN_MESSAGE_MAP(CExEditView, CView)
	//{{AFX_MSG_MAP(CExEditView)
	ON_COMMAND(ID_HUOQU, OnHuoqu)
	ON_COMMAND(ID_STORE, OnStore)
	ON_UPDATE_COMMAND_UI(ID_STORE, OnUpdateStore)
	ON_WM_CREATE()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CExEditView construction/destruction

CExEditView::CExEditView():m_sh("")
{
    m_sh.m_page1.m_bBold = FALSE;
    m_sh.m_page1.m_bItalic = FALSE;
    m_sh.m_page1.m_bUnderline = FALSE;
    m_sh.m_page2.m_nColor = 0;
    m_sh.m_page3.m_nFontSize = 12;
}

CExEditView::~CExEditView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CExEditView drawing

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

/////////////////////////////////////////////////////////////////////////////
// CExEditView printing

BOOL CExEditView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CExEditView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CExEditView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CExEditView diagnostics

#ifdef _DEBUG
void CExEditView::AssertValid() const
{
	CView::AssertValid();
}

void CExEditView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CExEditView message handlers

void CExEditView::OnHuoqu() 
{
	CExEditDoc* pDoc = GetDocument();
    m_rich.SetWindowText(pDoc->m_strText);
    m_rich.SetModify(FALSE);	
}

void CExEditView::OnStore() 
{
	CExEditDoc* pDoc = GetDocument();
    m_rich.GetWindowText(pDoc->m_strText);
    m_rich.SetModify(FALSE);
}

void CExEditView::OnUpdateStore(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_rich.GetModify());
}

int CExEditView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	CRect rect(0, 0, 0, 0);
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	m_rich.Create(ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN |
                  WS_CHILD | WS_VISIBLE | WS_VSCROLL, rect, this, 1);
	CHARFORMAT cf;
	Format(cf);
	m_rich.SetDefaultCharFormat(cf);
	return 0;
}

void CExEditView::Format(CHARFORMAT& cf)
{
    cf.cbSize = sizeof(CHARFORMAT);
    cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE |
                CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
    cf.dwEffects = (m_sh.m_page1.m_bBold ? CFE_BOLD : 0) |
                   (m_sh.m_page1.m_bItalic ? CFE_ITALIC : 0) |
                   (m_sh.m_page1.m_bUnderline ? CFE_UNDERLINE : 0);
    cf.yHeight = m_sh.m_page3.m_nFontSize * 20;
    switch(m_sh.m_page2.m_nColor) {
    case -1:
    case 0:
        cf.crTextColor = RGB(0, 0, 0);
        break;
    case 1:
        cf.crTextColor = RGB(255, 0, 0);
        break;
    case 2:
        cf.crTextColor = RGB(0, 255, 0);
        break;
    }
    cf.bCharSet = 0;
    cf.bPitchAndFamily = 0;
}

⌨️ 快捷键说明

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