반응형

CMDIEditApp.cpp

BOOL CMDIEditApp::InitInstance()함수 안에

AfxInitRichEdit( ); 를 추가


CMDIEditView

CMDIEditView.h 에 멤버변수추가

CRichEditCtrl m_rich;


CMDIEditView.cpp

void CMDIEditView::OnEditCut()
{
 // TODO: Add your command handler code here
 m_rich.Cut();
}

void CMDIEditView::OnEditCopy()
{
 // TODO: Add your command handler code here
 m_rich.Copy();
}

void CMDIEditView::OnEditPaste()
{
 // TODO: Add your command handler code here
 m_rich.Paste();
}

void CMDIEditView::OnEditUndo()
{
 // TODO: Add your command handler code here
 m_rich.Undo();
}

void CMDIEditView::OnFont()
{
 // TODO: Add your command handler code here
 CHARFORMAT cf = {0, };

 cf.dwMask = CFM_UNDERLINE;
 cf.dwEffects = CFE_UNDERLINE;

 cf.cbSize = sizeof(CHARFORMAT);

 m_rich.SetSelectionCharFormat(cf);
}




-> 활성화된 child window를 파악한다. (어떤 객체가 Active상태인지~)

CMDIEditMainFrame


CMainFrame.cpp


#include "MDIEditDoc.h"
#include "MDIEditView.h"


void CMainFrame::OnEditCut()
{
 // TODO: Add your command handler code here
 CMDIEditView *view = (CMDIEditView *)((CMDIChildWnd *)(MDIGetActive())->GetActiveView());
 view->m_rich.Cut();

}

void CMainFrame::OnEditPaste()
{
 // TODO: Add your command handler code here
 CMDIEditView *view = (CMDIEditView *)((CMDIChildWnd *)(MDIGetActive())->GetActiveView());
 view->m_rich.Paste();

}


CMDIChildFrame


CChildFrame.cpp


#include "MDIEditDoc.h"
#include "MDIEditView.h"


void CChildFrame::OnFont2()
{
 // TODO: Add your command handler code here
 CMDIEditView * view = (CMDIEditView *)GetActiveView();
 CHARFORMAT cf = {0, };
 
 cf.dwMask = CFM_UNDERLINE;
 cf.dwEffects = CFE_UNDERLINE;
 
 cf.cbSize = sizeof(CHARFORMAT);
 
 view->m_rich.SetSelectionCharFormat(cf);

}


CMDIEditDoc


CMDIEditDoc.cpp

#include "MDIEditView.h"


void CMDIEditDoc::Serialize(CArchive& ar)
{
 if (ar.IsStoring())
 {
  // TODO: add storing code here
  CMDIFrameWnd* MainFrm = (CMDIFrameWnd *)AfxGetMainWnd();
  CMDIChildWnd* ChildFrm = (CMDIChildWnd *)MainFrm->MDIGetActive();
  CMDIEditView* view = (CMDIEditView *)ChildFrm->GetActiveView();

  view->m_rich.SetSel(0,-1);
  CString str = view->m_rich.GetSelText();

  ar << str;

 }
 else
 {
  // TODO: add loading code here
 }
}

반응형

'WindowsPrograming' 카테고리의 다른 글

UpdateWindow(), InvalidateRect()  (0) 2007.03.10
자주 쓰이는 API함수  (0) 2007.03.10
API 기본 파일  (0) 2007.03.10
Posted by Real_G