原始 Win32 中的 Rich Edit 控件

发布于 2024-07-04 09:07:57 字数 973 浏览 9 评论 0原文

Rich Edit Controls 的文档真的像看起来那么糟糕(错误吗?)? 现在,我正在手动调用 LoadLibrary("riched20.dll") 以便显示 Rich Edit 控件。 Rich Edit 的文档在使用 Rich Edit 控件的第一个代码示例中对此进行了很差的演示。

它讨论了调用 InitCommonControlsEx() 来添加视觉样式,但没有提及要传入哪些标志。

是否有更好的方法来加载 Rich Edit 控件?

http://msdn.microsoft.com/en-us/ library/bb787877(VS.85).aspx

这是我可以编写使其工作的唯一代码:

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

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.

It talks about calling InitCommonControlsEx() to add visual styles, but makes no mention of which flags to pass in.

Is there a better way to load a Rich Edit control?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

吐个泡泡 2024-07-11 09:07:57

我认为在创建任何公共控件之前您必须调用 CoInitializeEx。

不需要 LoadLibrary。 如果您链接到正确的 .lib 文件,exe 加载程序将为您处理这些详细信息。

I think you have to call CoInitializeEx before you create any of the common controls.

The LoadLibrary is not needed. If you link with the correct .lib file the exe-loader will take care of such details for you.

疯到世界奔溃 2024-07-11 09:07:57

是否没有可以链接到的导入库(可能是 riched20.lib)。 然后您就不必在运行时“手动”加载它。 这就是所有标准控件的工作原理。 创建项目时,VS 会自动添加对 user32.lib 的引用。

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.

影子的影子 2024-07-11 09:07:57

使用 MFC,RichEdit 控件就可以工作。

使用 InitCommonControlsEx() 加载 - ICC_USEREX_CLASSES 不会加载 RichEdit AFAIK,您不需要它,因为它只加载“标准”公共控件,其中不包括 richedit。 显然,您只需要调用它来启用 Windows 中的“视觉样式”,而不是让 RichEdits 工作。

如果您使用的是 2008,则需要包含 Msftedit.dll 并改用 MSFTEDIT_CLASS(MS 有时在向后兼容性方面很糟糕)。

文档确实建议您正确地进行 Win32 编程。

Using MFC, RichEdit controls just work.

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.

If you're using 2008, you want to include Msftedit.dll and use the MSFTEDIT_CLASS instead (MS are rubbish for backward compatibilty sometimes).

The docs do suggest you're doing it right for Win32 programming.

臻嫒无言 2024-07-11 09:07:57

许多年前,我遇到了同样的问题,是的,答案是手动加载 .dll。 据我所知,原因是RichEdit窗口类注册在riched20.dll的DllMain中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文