简单使用RichEdit2.0A

 

下载 本文演示程序源代码 9KB

通常我们用VC++提供的RichEdit会碰到很苦恼的事情----中文乱码和单字节汉字

中文乱码一般可以用SetFont解决,

而这个单字节汉字就非常的莫名其妙了,一旦出现单字节汉字,你每按一次backspace将只消除半个汉字,景象甚是恼人。

 

最终我向RichEdit2.0A靠拢了。RichEdit20a的汉字自动为WideChar,

乱码和单字节汉字都不见了。

 

下面介绍迅速在自己的程序中使用RichEdit20a的方法:(以对话框程序为例)

在对话框的资源编辑器中选择Custom Control(就是有一个人头的....)

放到对话框上之后右键打开该控件属性,Class指定为 RichEdit20A

(至于style和ex_style自定,各种值可以通过spy++获得)

属性页

                                   图: Custom 控件的属性页, Class为RichEdit20A

下面编译程序-----结果:程序自动退出了,why?没有AfxInitRichEdit( );?

不是的,跟我继续前进:

填加一个全局变量 HMODULE hMod;

在程序初始化开头: (比如CWinApp::InitInstance()开头)加上一句:   

                      hMod = LoadLibrary( TEXT( "riched20.dll" ) );

在程序退出前:(比如CWinApp::ExitInstance()里)

                      FreeLibrary( hMod );


在编译程序,RichEdit20A显身了,

 

RichEdit20a还有其他特性,你自己发掘吧

 

没有乱码、单字节的汉字。
 
来源: 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 ; }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值