// Visual C++ Text Editor // Terrence Ma // Modified from Inside Visual C++ // Add to ex12aDoc.h public: CString m_strText; // Add to ex12aDoc.cpp BOOL CEx12aDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; m_strText = "Hello (from CEx12aDoc::OnNewDocument)"; return TRUE; } void CEx12aDoc::OnEditClearDocument() { m_strText.Empty(); } void CEx12aDoc::OnUpdateEditClearDocument(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_strText.IsEmpty()); } // Add to ex12aView.h public: CRichEditCtrl m_rich; // Add to ex12aView.cpp int CEx12aView::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 CEx12aView::OnSize(UINT nType, int cx, int cy) { CRect rect; CView::OnSize(nType, cx, cy); GetClientRect(rect); m_rich.SetWindowPos(&wndTop, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_SHOWWINDOW); } void CEx12aView::OnTransferGetData() { CEx12aDoc* pDoc = GetDocument(); m_rich.SetWindowText(pDoc->m_strText); m_rich.SetModify(FALSE); } void CEx12aView::OnTransferStoreData() { CEx12aDoc* pDoc = GetDocument(); m_rich.GetWindowText(pDoc->m_strText); m_rich.SetModify(FALSE); } void CEx12aView::OnUpdateTransferStoreData(CCmdUI* pCmdUI) { pCmdUI->Enable(m_rich.GetModify()); }