RichEdit导致Dialog初始化失败

来源:互联网 发布:淘宝网店如何找上家 编辑:程序博客网 时间:2024/05/01 20:43

想做一个Tab窗口,结果报错,DEBUG发现是子窗口Create时出错,添加空窗口时没有错误,于是猜想可能是子窗口上的控件引起的错误,便新建一个测试工程,逐个窗口逐个控件地添加然后运行。果然在添加到Rich Edit的时候又出现了那个错误,上网一查,发现:

窗口中有RichEdit控件时需要在初始化函数中添加AfxInitRichEdit()

查了一下MSDN对AfxInitRichEdit()的解释如下:

This function is provided for backward compatibility. Applications created with Visual C++ .NET and later useAfxInitRichEdit2.

AfxInitRichEdit loads RICHED32.DLL to initialize version 1.0 of the rich edit control. To use version 2.0 and 3.0 of the rich edit control, RICHED20.DLL needs to be loaded. This is accomplished with a call toAfxInitRichEdit2. If you have dialog resources with the rich edit control created prior to Visual C++ .NET, the rich edit controls are automatically version 1.0. Rich edit controls inserted using the Visual C++ .NET Resource Editor are version 2.0.

To update rich edit controls in existing Visual C++ applications to version 2.0, open the .RC file as text, change the class name of each rich edit control from "RICHEDIT" to "RichEdit20a". Then replace the call toAfxInitRichEdit with AfxInitRichEdit2.

This function also initializes the common controls library, if the library hasn't already been initialized for the process. If you use the rich edit control directly from your MFC application, you should call this function to assure that MFC has properly initialized the rich edit control runtime. If you call the Create method of CRichEditCtrl, CRichEditView, or CRichEditDoc, you typically don't need to call this function, but in some cases it might be necessary.

Call this function to initialize the richeditcontrol for the application. It will also initialize the common controls library, if the library hasn’t already been initialized for the process. If you use thericheditcontrol directly from your MFC application, you should call this function to assure that MFC has properly initialized thericheditcontrol runtime. If you usericheditvia CRichEditCtrl,CRichEditView, orCRichEditDoc, you don't need to call this function。

还有很多人建议更通用的:InitCommonControls() & InitCommonControlsEx()