www.pudn.com > editor.rar > zucc_editerView.cpp
// zucc_editerView.cpp : implementation of the CZucc_editerView class
//
#include "stdafx.h"
#include "zucc_editer.h"
#include "zucc_editerDoc.h"
#include "zucc_editerView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CZucc_editerView
IMPLEMENT_DYNCREATE(CZucc_editerView, CView)
BEGIN_MESSAGE_MAP(CZucc_editerView, CView)
//{{AFX_MSG_MAP(CZucc_editerView)
ON_WM_SIZE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CZucc_editerView construction/destruction
CZucc_editerView::CZucc_editerView()
: m_ctrlEdit(NULL) //添加这一行初始化代码
{
// TODO: add construction code here
}
CZucc_editerView::~CZucc_editerView()
{
}
BOOL CZucc_editerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CZucc_editerView drawing
void CZucc_editerView::OnDraw(CDC* pDC)
{
CZucc_editerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CZucc_editerView printing
BOOL CZucc_editerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CZucc_editerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CZucc_editerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CZucc_editerView diagnostics
#ifdef _DEBUG
void CZucc_editerView::AssertValid() const
{
CView::AssertValid();
}
void CZucc_editerView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CZucc_editerDoc* CZucc_editerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CZucc_editerDoc)));
return (CZucc_editerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CZucc_editerView message handlers
void CZucc_editerView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
class
CRect rcClient;
GetClientRect( rcClient ); // 获取当前视图的客户区大小
// if ( m_ctrlEdit ) delete m_ctrlEdit;
m_ctrlEdit = new CEdit();
m_ctrlEdit->Create( ES_MULTILINE | WS_CHILD | WS_VISIBLE
| WS_HSCROLL | ES_AUTOHSCROLL // 自动水平滚动
| WS_VSCROLL | ES_AUTOVSCROLL , // 自动垂直滚动
rcClient, this, 201); // 创建多行编辑控件
CZucc_editerDoc* pDoc = GetDocument(); // 获取与视图相关联的文档指针
// 以下是将文档中的m_strContent内容全部赋给str
CString str;
int nLines = (int)pDoc->m_strContent.GetSize();
for ( int i=0; im_strContent.GetAt( i );
str = str + "\r\n"; // 换行
}
m_ctrlEdit->SetTabStops( 16 ); // 设置Tab符大小
m_ctrlEdit->SetWindowText( str ); // 将文档内容传给控件
}
void CZucc_editerView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect rcClient;
GetClientRect( rcClient );
if ( m_ctrlEdit )
m_ctrlEdit->MoveWindow( rcClient ); // 改变编辑控件窗口大小
}