5

I added a link to RichEdit, use CFM_LINK/CHARFORMAT2 structure. But I can't figure out how to remove the underline effect. I tried:

SendMessage(richEditHWND, EM_AUTOURLDETECT, FALSE, NULL);
SendMessage(richEditHWND, EM_SETEDITSTYLEEX, 0, SES_EX_HANDLEFRIENDLYURL);

CHARFORMAT2 cf2;
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.dwMask = CFM_LINK| CFM_UNDERLINE | CFM_COLOR | CFM_LINKPROTECTED;
cf2.dwEffects = CFE_LINK| CFE_UNDERLINE | CFE_LINKPROTECTED;
cf2.crTextColor = RGB(255, 0, 0);
cf2.bUnderlineType = CFU_UNDERLINENONE;
SendMessage(richEditHWND, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);

But it don'n work.
Another way is set underline color to white color, which is the RichEdit background color, but it is a hacky way, make character like q, j,... being cut apart, also show the line when select text.
So what's the correct way to do this?
Note: I'm using RICHEDIT50W class.

NoName
  • 7,940
  • 13
  • 56
  • 108

3 Answers3

3

You can do this using a friendly-name hyperlink. These let you specify arbitrary text (along with its own color and formatting) that is used for display, and the actual URL is hidden.

By default, friendly-name hyperlink text is also displayed in blue with a blue underline unless the name text is formatted with an explicit color. Explicit formatting takes precedence

The displayed text needs to have the CFE_LINK and CFE_LINKPROTECTED styles, along with explicit color and formatting styles. You then set the URL using the ITextRange2::SetURL method.

The MSDN blog post RichEdit Friendly Name Hyperlinks has a more detailed description of how to use them.

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
  • Not worked. I updated my code in the question. In your link, they say I can change color of the link, not able to hide underline. The other comments on that page also confirm this. – NoName Jan 22 '16 at 06:43
0

I just encountered the same problem recently and I just found that it's a bug of Richedit library. When I updated it from v4.1 to v5.0 the underline could be removed with no issues

-2

Try sending an EM_AUTOURLDETECT message to the RichEdit control with wParam=0, lParam=0

"Specify 0 to disable automatic link detection...": https://msdn.microsoft.com/en-us/library/windows/desktop/bb787991(v=vs.85).aspx

kerem
  • 2,699
  • 1
  • 32
  • 37