CRichEdit control Hyperlink color change not working

Harsh Shankar 0 Reputation points
2024-07-05T05:31:17+00:00

I have derived a class from CRichEdit and the control contains multiple hyperlinks. While every thing works as expected, customer wants to change the color of the hyperlinks to red. I tried many things, yet the hyperlink still shows in blue color. Here is the code that fails:

for (int nLstCnt = 0; nLstCnt < nListCount; nLstCnt++)
{
    MESSAGELIST& objMsgList = m_arrMessageList[nLstCnt];
    SetSel(objMsgList.nStartPos + 1, objMsgList.nStartPos + objMsgList.strFormatString.GetLength() - 1);
    CHARFORMAT2 cf;
    memset(&cf, 0, sizeof(CHARFORMAT2));
    cf.cbSize = sizeof(CHARFORMAT2);
    cf.dwMask = CFM_LINK | CFM_COLOR;
    cf.dwEffects = CFE_LINK;
    cf.crTextColor = RGB(0xFF, 0x00, 0x00);
    SetSelectionCharFormat(cf);
}

It feels like if I use CFM_LINK, CFM_COLOR does not work. Do I am missing something? Any help will be appreciated.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,174 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,754 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 85,701 Reputation points
    2024-07-05T07:10:02.49+00:00

    It works for me with CFE_UNDERLINE (also bUnderlineColor for just the line color) :

    User's image


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.