Valhalla Legends Forums Archive | General Programming | RICHEDITs and links

AuthorMessageTime
Myndfyr
Okay.... this is getting on my nerves.

I'm trying to come up with a way to have a link in a rich edit control while having the link destination be something arbitrary.

The first suggestion I found was in CodeProject, which involved adding some kind of \v field to the RTF.  It displayed correctly, but I was unable to change the color of the text; if it was on a dark background, the text would be white; and if on a light background, the text would be blue.

The function of this code was to not only adapt the link and destination to RTF but also to insert the specified RTF, as well as convert its style to a link style.  This is done with the EM_SETCHARFORMAT message to the rich edit control.  You specify CFM_LINK in the dwMask field and you're set.  I've tried setting CFM_COLOR in the field to no avail; however, CFM_BACKCOLOR works, and it's how I reproduced the behavior I described above.

Well, I knew WordPad in WinXP could do it, so I decided to load up Spy++.  It turns out that C# uses the window class RICHEDIT20W and WordPad uses RICHEDIT50W (in msftedit.dll).  Now I'm not getting any link notifications whatsoever.

After creating the control, I send it the EM_SETEVENTMASK message, including the EMN_LINK flag, and I'm watching for WM_NOTIFY in the rich edit control's WndProc as well as the parent's WndProc.  I'm not getting anything back.

Any thoughts?
January 31, 2006, 8:50 PM
Skywing
Perhaps something is overwriting your event mask with a subsequent EM_SETEVENTMASK request.

You might try sending EM_GETEVENTMASK after you are done initializing to verify that the control still has the value you are expecting.

I would also try setting Spy++ to watch all messages for the UI thread to see if the notification is getting sent somewhere unexpected (perhaps .NET is imposing another hidden window between you and the control or something that is eating the notification).

Out of curiousity, do links created from say http protocol urls (http://www.example.com) if you turn on automatic link detection also not send you the notifications for mouse events?
February 1, 2006, 1:56 AM
Myndfyr
[quote author=Skywing link=topic=14067.msg144041#msg144041 date=1138758999]
Perhaps something is overwriting your event mask with a subsequent EM_SETEVENTMASK request.

You might try sending EM_GETEVENTMASK after you are done initializing to verify that the control still has the value you are expecting.
[/quote]
That was one of the first things I checked.  In fact, the return from the first EM_GETEVENTMASK indicates that this flag is already set (probably for the LinkClicked event of the RichTextBox control), but I am unsure.

[quote author=Skywing link=topic=14067.msg144041#msg144041 date=1138758999]
I would also try setting Spy++ to watch all messages for the UI thread to see if the notification is getting sent somewhere unexpected (perhaps .NET is imposing another hidden window between you and the control or something that is eating the notification).
[/quote]
I've done that too.  I checked the properties of the control that is clearly the RichEdit (it has RICHEDIT20W as the class style and has my text in the caption box), its parent was an unknown window class (some gibberish made up by .NET no doubt), and then its parent was the main form.  So I'm fairly certain I'm checking for notification in the right place (the rich text box sits on a user composite control, which then sits on the form).

When I was watching with Spy++, I never saw any WM_NOTIFY events.  I did see a couple WM_NOTIFYPARENT when I clicked on the link, but that's not what the documentation tells me I should see.

[quote author=Skywing link=topic=14067.msg144041#msg144041 date=1138758999]
Out of curiousity, do links created from say http protocol urls (http://www.example.com) if you turn on automatic link detection also not send you the notifications for mouse events?
[/quote]
This is not something I've checked.  However, the person who write the documentation for this particular project said to disable automatic link detection.  The emitted RTF is something like:
\v http://www.google.com # Google \v0

He said that enabling automatic link detection would cause the actual URL to show up, which is something I'd prefer to avoid.
February 1, 2006, 3:05 AM
Skywing
I'd go ahead and give autourldetection a try.

Also, what happens if you just use CFE_LINK for some text without the special formatting characters?

Are you inserting those characters directly as RTF, or as plain text that is getting potentially converted into the wrong thing?
February 1, 2006, 6:46 PM

Search