如何在MFC中使用richedit控件

编程入门 行业动态 更新时间:2024-10-27 16:39:45
如何在MFC中使用richedit控件_RICHEDIT_VER超过2.1(How to use richedit control _RICHEDIT_VER over 2.1 in MFC)

我想在MFC中使用Rich编辑控件的下划线颜色

但是,在afxwin.h中,_RICHEDIT_VER定义了0x210。 喜欢这个,

#define _RICHEDIT_VER 0x0210

我正在加载'msftedit.dll'(8.1版本)和Windows10 SDK(10.0.16299.0)但是,bUnderlineColor在Richedit.h中编码

#if (_RICHEDIT_VER >= 0x0800) BYTE bUnderlineColor; // Underline color #endif

如果我不使用包装类(CRichEditCtrl),我可以在MFC项目中使用它。 如何?

I'd like to use Rich edit control's underline color in MFC

but, in afxwin.h, _RICHEDIT_VER define 0x210. like this,

#define _RICHEDIT_VER 0x0210

I'm loading 'msftedit.dll'(8.1 Version) and Windows10 SDK (10.0.16299.0) but, bUnderlineColor is coded in Richedit.h

#if (_RICHEDIT_VER >= 0x0800) BYTE bUnderlineColor; // Underline color #endif

If I don't use wrapping class(CRichEditCtrl), Can I use this in MFC project. and How?

最满意答案

您可以声明自己的结构并添加bUnderlineColor 。 在CRichEdit::SendMessage(EM_SETCHARFORMAT...)

这种方法很糟糕。 也许有更好的方法来说服MFC合作。

#ifdef UNICODE struct MY_CHARFORMAT8 : _charformatw //<--- edited #else struct MY_CHARFORMAT8 : _charformat #endif { WORD wWeight; // Font weight (LOGFONT value) SHORT sSpacing; // Amount to space between letters COLORREF crBackColor; // Background color LCID lcid; // Locale ID union { DWORD dwReserved; // Name up to 5.0 DWORD dwCookie; // Client cookie opaque to RichEdit }; SHORT sStyle; // Style handle WORD wKerning; // Twip size above which to kern char pair BYTE bUnderlineType; // Underline type BYTE bAnimation; // Animated text like marching ants BYTE bRevAuthor; // Revision author index BYTE bUnderlineColor; // Underline color }; MY_CHARFORMAT8 format; memset(&format, sizeof(format), 0); format.cbSize = sizeof(format); format.dwMask = CFM_UNDERLINETYPE | CFM_UNDERLINE; format.dwEffects = CFE_UNDERLINE; format.crBackColor = RGB(255,0,0); format.bUnderlineType = CFU_UNDERLINEHAIRLINE; format.bUnderlineColor = 0x06; //red underline color m_richedit.SetSel(0, -1); m_richedit.SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);

需要初始调用AfxInitRichEdit()

必须使用Create (不使用SubclassDlgItem或DDX_Control )手动Create丰富的编辑控件,例如:

m_richedit.Create(ES_MULTILINE | WS_VISIBLE | WS_CHILD, rc, this, id);

结果: 在此处输入图像描述

You can declare your own structure and add bUnderlineColor. Use this in CRichEdit::SendMessage(EM_SETCHARFORMAT...)

This method is hack though. Maybe there is a better way to convince MFC to cooperate.

#ifdef UNICODE struct MY_CHARFORMAT8 : _charformatw //<--- edited #else struct MY_CHARFORMAT8 : _charformat #endif { WORD wWeight; // Font weight (LOGFONT value) SHORT sSpacing; // Amount to space between letters COLORREF crBackColor; // Background color LCID lcid; // Locale ID union { DWORD dwReserved; // Name up to 5.0 DWORD dwCookie; // Client cookie opaque to RichEdit }; SHORT sStyle; // Style handle WORD wKerning; // Twip size above which to kern char pair BYTE bUnderlineType; // Underline type BYTE bAnimation; // Animated text like marching ants BYTE bRevAuthor; // Revision author index BYTE bUnderlineColor; // Underline color }; MY_CHARFORMAT8 format; memset(&format, sizeof(format), 0); format.cbSize = sizeof(format); format.dwMask = CFM_UNDERLINETYPE | CFM_UNDERLINE; format.dwEffects = CFE_UNDERLINE; format.crBackColor = RGB(255,0,0); format.bUnderlineType = CFU_UNDERLINEHAIRLINE; format.bUnderlineColor = 0x06; //red underline color m_richedit.SetSel(0, -1); m_richedit.SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);

Requires initial call to AfxInitRichEdit()

Rich edit control has to be created manually with Create (not using SubclassDlgItem or DDX_Control), example:

m_richedit.Create(ES_MULTILINE | WS_VISIBLE | WS_CHILD, rc, this, id);

Result: enter image description here

更多推荐

本文发布于:2023-08-02 07:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1372247.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   如何在   MFC   richedit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!