扩展 DaveCamp 的答案,该CHARFORMAT2W
结构包含一个bReserved1
条目:
typedef struct _charformat2w
{
UINT cbSize;
DWORD dwMask;
DWORD dwEffects;
...
BYTE bReserved1;
} CHARFORMAT2W;
但是,如果您查看最新的 (8.0) SDK,该bReserved1
条目现在已被赋予下划线颜色:
typedef struct _charformat2w
{
UINT cbSize;
DWORD dwMask;
DWORD dwEffects;
...
#if (_RICHEDIT_VER >= 0x0800)
BYTE bUnderlineColor; // Underline color
#endif
} CHARFORMAT2W;
这被定义为 Widows 8 功能 ( _RICHEDIT_VER >= 0x0800
)。
设置下划线颜色的方法是戴夫的回答:
CHARFORMAT2 format;
format.cbSize = sizeof(format);
format.dwMask = CFM_UNDERLINETYPE | CFM_UNDERLINE;
format.dwEffects = CFE_UNDERLINE;
format.bUnderlineType = CFU_UNDERLINEWAVE;
format.bUnderlineColor = 0x05;
SendMessage(hWndEdit,EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &format);
剩下的技巧是颜色BYTE
值。它们尚未记录在案,但有 16 种颜色:
UnderlineColor_Black = 0x00;
UnderlineColor_Blue = 0x01;
UnderlineColor_Aqua = 0x02;
UnderlineColor_Lime = 0x03;
UnderlineColor_Fuchsia = 0x04;
UnderlineColor_Red = 0x05;
UnderlineColor_Yellow = 0x06;
UnderlineColor_White = 0x07;
UnderlineColor_Navy = 0x08;
UnderlineColor_Teal = 0x09;
UnderlineColor_Green = 0x0A;
UnderlineColor_Purple = 0x0B;
UnderlineColor_Maroon = 0x0C;
UnderlineColor_Olive = 0x0D;
UnderlineColor_DkGray = 0x0E;
UnderlineColor_LtGray = 0x0F;

编辑:将颜色名称从 更改Cyan
为Aqua
。固定拼写Fuchsia
。
注意:任何发布到公共领域的代码。无需归属。