现象:运行时程序直接退出;
原因:使用此控件前要进行初始化;
解决:最好在程序入口处(WinMain函数)作如下处理
1)MFC程序:调用AfxInitRichEdit()
2)WIN32程序:在WinMain中加载下动态库riched20.dll,如下所示
HMODULE richEditModule = LoadLibrary("riched20.dll"); ...... FreeLibrary(richEditModule);
3)WIN32程序:网络上说调用InitCommonControls()即可,但我没有成功过,可能是RichEdit不属于Common Control吧
微软官方解释:
If you are using a rich edit control in a dialog box (regardless whether your application is SDI, MDI, or dialog-based), you must call AfxInitRichEdit on
注:以上解决方法也同样适应于RichXXX控件,如CRichEditView;