[MFC] 리치에디트 2.0 콘트롤 사용하기
리치에디트 콘트롤 2.0은 윈95부터 지원 되었지만,
왠일인지 마소는 2.0 콘트롤을 MFC 클래스나 VS 표준 콘트롤로 채용하지
않고 있습니다.
리치에디트 2.0은 undo/redo 기능도 있고, url 자동 감지 기능,
1.0 보다 텍스트에 훨씬 다양한 효과를 줄수도 있으며,
기타 1.0 보다 많은 풍부한 기능을 가지고 있습니다.
그래서, 단 몇 줄 만 추가하면 기존 MFC의 리치에디트 뷰나 콘트롤을
그대로 사용하면서도 리치에디트 2.0 콘트롤을 사용할 수 있는 방법을 알려드리겠습니다.
(다 이렇게 쓰고 있는지도 모르겠군요.^^)
어쨌든... 만약 RICH2View란 리치에디트 1.0 뷰를 상속한 뷰 클래스가 있다면 일단 그 클래스에
HINSTANCE m_hinstRichEdit2;
란 데이터 멤버를 추가합니다.
그런 후, 그 생성자에서 다음처럼 리치에디트 2.0 dll을 로드하고
앞서 추가한 멤버에 할당합니다.
RICH2View::RICH2View()
{
// TODO: add construction code here
m_hinstRichEdit2 = LoadLibraryA("RICHED20.DLL");
}
{
// TODO: add construction code here
m_hinstRichEdit2 = LoadLibraryA("RICHED20.DLL");
}
파괴자에서는 다음처럼 해제시키면 됩니다.
RICH2View::~RICH2View()
{
if(m_hinstRichEdit2)
FreeLibrary(m_hinstRichEdit2);
}
{
if(m_hinstRichEdit2)
FreeLibrary(m_hinstRichEdit2);
}
그런 후, PreCreateWindow(...) 에서 사용할 클래스 이름을 리치에디트 2.0 클래스로
바꿔치기 하는 겁니다. 다음처럼요.
BOOL RICH2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
AfxInitRichEdit();
if(m_hinstRichEdit2)
{
#ifdef UNICODE
m_strClass = "RichEdit20W";
#else
m_strClass = "RichEdit20A";
#endif
if(!CCtrlView::PreCreateWindow(cs))
return FALSE;
cs.lpszName = _T("");
cs.cx = cs.cy = 100; // necessary to avoid bug with ES_SELECTIONBAR and zero for cx and cy
cs.style |= WS_CLIPSIBLINGS;
return TRUE;
}
else
{
AfxMessageBox(IDS_RICHEDIT2_LOAD_FAILED);
return CRichEditView::PreCreateWindow(cs);
}
}
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
AfxInitRichEdit();
if(m_hinstRichEdit2)
{
#ifdef UNICODE
m_strClass = "RichEdit20W";
#else
m_strClass = "RichEdit20A";
#endif
if(!CCtrlView::PreCreateWindow(cs))
return FALSE;
cs.lpszName = _T("");
cs.cx = cs.cy = 100; // necessary to avoid bug with ES_SELECTIONBAR and zero for cx and cy
cs.style |= WS_CLIPSIBLINGS;
return TRUE;
}
else
{
AfxMessageBox(IDS_RICHEDIT2_LOAD_FAILED);
return CRichEditView::PreCreateWindow(cs);
}
}
그리고 마지막으로, OnDestroy() 에서 다음 내용을 코멘트 처리해주시면 됩니다.
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
{
pActiveItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
{
pActiveItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
확인은 스파이++로 찍어보시면 되겠죠.
출처 : 데브피아 조정환(chosmos)님의 글