我想在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 0x0210I'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 #endifIf 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:
更多推荐
发布评论