windows 原始 Win32 中的丰富编辑控件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/85427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:13:47  来源:igfitidea点击:

Rich Edit Control in raw Win32

windowswinapirichedit

提问by user16408

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

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);

采纳答案by gbjbaanb

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 docsdo suggest you're doing it right for Win32 programming.

文档做建议你这样做是正确的Win32编程。

回答by Brannon

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中。

回答by Ferruccio

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 的引用。

回答by Nils Pipenbrinck

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 将为您处理此类详细信息。