• Welcome to Valhalla Legends Archive.
 

RICHEDITs and links

Started by MyndFyre, January 31, 2006, 02:50 PM

Previous topic - Next topic

MyndFyre

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?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

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?

MyndFyre

Quote from: Skywing on January 31, 2006, 07:56 PM
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.
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 from: Skywing on January 31, 2006, 07:56 PM
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).
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 from: Skywing on January 31, 2006, 07:56 PM
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?
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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

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?