Replacing "RICHEDIT" control with "RichEdit20A"

时间:2013-08-14 09:02:44
【文件属性】:
文件名称:Replacing "RICHEDIT" control with "RichEdit20A"
文件大小:15KB
文件格式:ZIP
更新时间:2013-08-14 09:02:44
RichEdit 来源: http://www.codeguru.com/cpp/controls/richedit/article.php/c2389/CRichEditCtrlEx--Replacing-RICHEDIT-control-with-RichEdit20A.htm While writing a dev notes Visual Studio plug in, I wanted the rich edit control in a dialog to understand URL's so developers could add links to sites and email addresses. After talking to "Long John", he led me to the easy way of doing it, and now I am posting the work for others. Basically this requires CRichEditCtrlEx to use the new rich edit DLL RICHED20.DLL. The first thing to do it change the window class name of the rich edit controls from "RICHEDIT" to "RichEdit20A" in the *.rc file. Next, we create a class derived from CRichEditCtrl called CRichEditCtrlEx and override the Create() method: class CRichEditCtrlEx : public CRichEditCtrl { public: CRichEditCtrlEx(); virtual ~CRichEditCtrlEx(); // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL( CRichEditCtrlEx ) public: virtual BOOL Create( DWORD in_dwStyle, const RECT& in_rcRect, CWnd* in_pParentWnd, UINT in_nID ); //}}AFX_VIRTUAL // Generated message map functions protected: //{{AFX_MSG( CRichEditCtrlEx ) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; Now implement the Create() method like this: Post a comment Email Article Print Article Share Articles Digg del.icio.us Newsvine Facebook Google LinkedIn MySpace Reddit Slashdot StumbleUpon Technorati Twitter Windows Live YahooBuzz FriendFeed BOOL CRichEditCtrlEx::Create(DWORD in_dwStyle, const RECT& in_rcRect, CWnd* in_pParentWnd, UINT in_nID) { if( ! ::AfxInitRichEditEx() ) { return FALSE ; } CWnd* l_pWnd = this ; return l_pWnd->Create( _T( "RichEdit20A" ), NULL, in_dwStyle, in_rcRect, in_pParentWnd, in_nID ); } This is almost exactly what is in CRichEditCtrl::Create(), except the different window class name, and the call to AfxInitRichEdit() has been changed to AfxInitRichEditEx() which first calls AfxInitRichEdit (we do not want to break the normal CRichEditCtrl). In the RichEditCtrlEx.h file, you need to add the DLL holder class and function prototype: class _AFX_RICHEDITEX_STATE { public: _AFX_RICHEDITEX_STATE(); virtual ~_AFX_RICHEDITEX_STATE(); HINSTANCE m_hInstRichEdit20 ; }; BOOL PASCAL AfxInitRichEditEx(); Now, in the source code, add the implementation: _AFX_RICHEDITEX_STATE::_AFX_RICHEDITEX_STATE() { m_hInstRichEdit20 = NULL ; } _AFX_RICHEDITEX_STATE::~_AFX_RICHEDITEX_STATE() { if( m_hInstRichEdit20 != NULL ) { ::FreeLibrary( m_hInstRichEdit20 ) ; } } _AFX_RICHEDITEX_STATE _afxRichEditStateEx ; BOOL PASCAL AfxInitRichEditEx() { if( ! ::AfxInitRichEdit() ) { return FALSE ; } _AFX_RICHEDITEX_STATE* l_pState = &_afxRichEditStateEx ; if( l_pState->m_hInstRichEdit20 == NULL ) { l_pState->m_hInstRichEdit20 = LoadLibraryA("RICHED20.DLL") ; } return l_pState->m_hInstRichEdit20 != NULL ; }
【文件预览】:
StdAfx.h
RichEdit20.dsp
Release
----RichEdit20.exe(20KB)
res
----linkhand.cur(326B)
----RichEdit20.rc2(402B)
----RichEdit20.ico(1KB)
RichEdit20.h
MainDialog.cpp
RichEditCtrlEx.cpp
resource.h
RichEdit20.rc
RichEdit20.cpp
StdAfx.cpp
RichEditCtrlEx.h
MainDialog.h

网友评论