Is the documentation for Rich Edit Controls really as bad (wrong?) as it seems to be? Right now I'm manually calling LoadLibrary("riched20.dll") in order to get a Rich Edit Control to show up. The documentation for Rich Edit poorly demonstrates this in the first code sample for using Rich Edit controls.
Rich Edit Controls的文档是否真的像看起来一样糟糕(错误?)?现在我手动调用LoadLibrary(“riched20.dll”)以显示Rich Edit Control。 Rich Edit的文档在使用Rich Edit控件的第一个代码示例中很难证明这一点。
It talks about calling InitCommonControlsEx() to add visual styles, but makes no mention of which flags to pass in.
它讨论了调用InitCommonControlsEx()来添加视觉样式,但没有提到要传入哪些标志。
Is there a better way to load a Rich Edit control?
有没有更好的方法来加载Rich Edit控件?
http://msdn.microsoft.com/en-us/library/bb787877(VS.85).aspx
Here's the only code I could write to make it work:
这是我可以编写的唯一代码,以使其工作:
#include "Richedit.h"
#include "commctrl.h"
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_USEREX_CLASSES; //Could be 0xFFFFFFFF and it still wouldn't work
InitCommonControlsEx(&icex); //Does nothing for Rich Edit controls
LoadLibrary("riched20.dll"); //Manually? For real?
hWndRichEdit = CreateWindowEx(
ES_SUNKEN,
RICHEDIT_CLASS,
"",
WS_BORDER | WS_VISIBLE | WS_CHILD,
2, 2, 100, 24,
hWnd, (HMENU) ID_RICH_EDIT, hInst, NULL);
4 个解决方案
#1
2
Using MFC, RichEdit controls just work.
使用MFC,RichEdit控件正常工作。
Loading with InitCommonControlsEx() - ICC_USEREX_CLASSES doesn't load RichEdit AFAIK, you don't need it as it only does the 'standard' common controls, which don't include richedit. Apparently you only need to call this to enable 'visual styles' in Windows, not to get RichEdits working.
使用InitCommonControlsEx()加载 - ICC_USEREX_CLASSES不加载RichEdit AFAIK,您不需要它,因为它只执行不包含richedit的“标准”公共控件。显然你只需要调用它来启用Windows中的“视觉样式”,而不是让RichEdits工作。
If you're using 2008, you want to include Msftedit.dll and use the MSFTEDIT_CLASS instead (MS are rubbish for backward compatibilty sometimes).
如果您使用的是2008,则需要包含Msftedit.dll并使用MSFTEDIT_CLASS(MS有时会出现向后兼容性的垃圾)。
The docs do suggest you're doing it right for Win32 programming.
文档确实建议你正在为Win32编程做正确的事情。
#2
2
Many years ago, I ran into this same issue, and yes, the answer was to load the .dll manually. The reason, as far as I can remember, is that the RichEdit window class is registered in DllMain of riched20.dll.
很多年前,我遇到了同样的问题,是的,答案是手动加载.dll。据我所知,原因是RichEdit窗口类在riched20.dll的DllMain中注册。
#3
1
Isn't there an import library (maybe riched20.lib) that you can link to. Then you won't have to load it "manually" at run time. That's how all the standard controls work. VS automatically adds a reference to user32.lib when you create a project.
是不是可以链接到的导入库(可能是riched20.lib)。然后,您不必在运行时“手动”加载它。这就是所有标准控件的工作原理。创建项目时,VS会自动添加对user32.lib的引用。
#4
0
I think you have to call CoInitializeEx before you create any of the common controls.
我认为你必须在创建任何常用控件之前调用CoInitializeEx。
The LoadLibrary is not needed. If you link with the correct .lib file the exe-loader will take care of such details for you.
不需要LoadLibrary。如果你链接到正确的.lib文件,exe-loader将为你处理这些细节。
#1
2
Using MFC, RichEdit controls just work.
使用MFC,RichEdit控件正常工作。
Loading with InitCommonControlsEx() - ICC_USEREX_CLASSES doesn't load RichEdit AFAIK, you don't need it as it only does the 'standard' common controls, which don't include richedit. Apparently you only need to call this to enable 'visual styles' in Windows, not to get RichEdits working.
使用InitCommonControlsEx()加载 - ICC_USEREX_CLASSES不加载RichEdit AFAIK,您不需要它,因为它只执行不包含richedit的“标准”公共控件。显然你只需要调用它来启用Windows中的“视觉样式”,而不是让RichEdits工作。
If you're using 2008, you want to include Msftedit.dll and use the MSFTEDIT_CLASS instead (MS are rubbish for backward compatibilty sometimes).
如果您使用的是2008,则需要包含Msftedit.dll并使用MSFTEDIT_CLASS(MS有时会出现向后兼容性的垃圾)。
The docs do suggest you're doing it right for Win32 programming.
文档确实建议你正在为Win32编程做正确的事情。
#2
2
Many years ago, I ran into this same issue, and yes, the answer was to load the .dll manually. The reason, as far as I can remember, is that the RichEdit window class is registered in DllMain of riched20.dll.
很多年前,我遇到了同样的问题,是的,答案是手动加载.dll。据我所知,原因是RichEdit窗口类在riched20.dll的DllMain中注册。
#3
1
Isn't there an import library (maybe riched20.lib) that you can link to. Then you won't have to load it "manually" at run time. That's how all the standard controls work. VS automatically adds a reference to user32.lib when you create a project.
是不是可以链接到的导入库(可能是riched20.lib)。然后,您不必在运行时“手动”加载它。这就是所有标准控件的工作原理。创建项目时,VS会自动添加对user32.lib的引用。
#4
0
I think you have to call CoInitializeEx before you create any of the common controls.
我认为你必须在创建任何常用控件之前调用CoInitializeEx。
The LoadLibrary is not needed. If you link with the correct .lib file the exe-loader will take care of such details for you.
不需要LoadLibrary。如果你链接到正确的.lib文件,exe-loader将为你处理这些细节。