Board index » cppbuilder » Hyperlink in RichEdit

Hyperlink in RichEdit


2005-12-06 10:23:26 AM
cppbuilder111
I have a vague memory of using Hot links in a TRichEdit Control some time
several years ago. However I cannot find any info on this and of course I've
forgotten what I did.
The link is to be situated in a Help about box. Besides info on version etc.
I want to have a URL to my website and a mailto: link to a support email
address. Hence it doesn't have to be in a TRichEdit at all. I just think
that's what I used once upon a time.
--
Perre
Sorry my site is only in Swedish as of now
www.kostforum.se
 
 

Re:Hyperlink in RichEdit

"Per Elmsäter" < XXXX@XXXXX.COM >wrote in message
Quote
I have a vague memory of using Hot links in a TRichEdit Control
some time several years ago. However I cannot find any info on
this and of course I've forgotten what I did.
Unless you are running under XP, TRichEdit does not support hyperlinks.
TRichEdit uses the Richedit v1.0 control. You must enable Richedit v2.0+
support in order to use hyperlinks. Under XP, hyperlinks can be used with
TRichEdit because XP maps Richedit v1.0 to use v3.0 transparently. Have a
look at the following site for details about using Richedit v2.0 and v3.0
with TRichEdit:
home.att.net/~robertdunn/Yacs.html
Quote
I want to have a URL to my website and a mailto: link to a
support email address.
How about using TLabel instead of TRichEdit? Simply provide an OnClick
event handler to call the Win32 API ShellExecute() function, ie:
ShellExecute(NULL, "open", "mailto: XXXX@XXXXX.COM ", 0, 0, SW_SHOWNORMAL);
ShellExecute(NULL, "open", "www.mysite.com", 0, 0,
SW_SHOWNORMAL);
You can use the TLabel's Font, Color, and Cursor properties to make it look
like a hyperlink.
Quote
Hence it doesn't have to be in a TRichEdit at all.
Good, because that only complicates things.
Gambit
 

Re:Hyperlink in RichEdit

Per Elmsäter wrote:
Quote
I have a vague memory of using Hot links in a TRichEdit Control some time
several years ago.
Using links in a TRichEdit is possible in Win98 up to XP.
Try the following code:
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
unsigned mask = SendMessage(RichEdit1->Handle,
EM_GETEVENTMASK, 0, 0);
SendMessage(RichEdit1->Handle, EM_SETEVENTMASK,
0, mask | ENM_LINK);
SendMessage(RichEdit1->Handle, EM_AUTOURLDETECT,
true, 0);
RichEdit1->Text = "The Bridges Publishing Web"
" Site is located at www.bridgespublishing.com. Check"
" it out.";
}
void __fastcall TForm1::WndProc(
Messages::TMessage &Message)
{
if (Message.Msg == WM_NOTIFY)
{
if (((LPNMHDR)Message.LParam)->code ==EN_LINK)
{
ENLINK* p = (ENLINK *)Message.LParam;
if (p->msg == WM_LBUTTONDOWN)
{
SendMessage(RichEdit1->Handle,
EM_EXSETSEL, 0, (LPARAM)&(p->chrg));
ShellExecute(Handle, "open",
RichEdit1->SelText.c_str(), 0, 0,
SW_SHOWNORMAL);
}
}
}
TForm::WndProc(Message);
}
class TForm1 : public TForm
{
__published: // IDE-managed Components
TRichEdit *RichEdit1;
private: // User declarations
void __fastcall WndProc( Messages::TMessage &Message);
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
The example comes obviously from www.bridgespublishing.com.
Sorry that I did not note the author.
Hans.
 

{smallsort}

Re:Hyperlink in RichEdit

Per Elmsäter wrote:
Quote
I have a vague memory of using Hot links in a TRichEdit Control some time
several years ago. However I cannot find any info on this and of course I've
forgotten what I did.

The link is to be situated in a Help about box. Besides info on version etc.
I want to have a URL to my website and a mailto: link to a support email
address. Hence it doesn't have to be in a TRichEdit at all. I just think
that's what I used once upon a time.

Assuming you have an about form and a label on it, I use this :-
//---------------------------------------------------------------------------
void __fastcall TAboutForm::Label1MouseMove(TObject *Sender,TShiftState Shift,int X,int Y)
{
Screen->Cursor=crHandPoint; Label1->Font->Color=clBlue;
}
//---------------------------------------------------------------------------
void __fastcall TAboutForm::FormMouseMove(TObject *Sender,TShiftState Shift,int X,int Y)
{
Screen->Cursor=crDefault; Label1->Font->Color=clRed;
}
//---------------------------------------------------------------------------
void __fastcall TAboutForm::Label1Click(TObject *Sender)
{
ShellExecute(NULL,"open","www.dkcomputing.co.uk",NULL,NULL,SW_SHOW);
}
//---------------------------------------------------------------------------
--
Mark Jacobs
www.dkcomputing.co.uk
 

Re:Hyperlink in RichEdit

Thanks all of you.
The TLabel approach will fit my current approach best and I'll look into
that.
However I'll be needing the RichEdit solution Hans supplied at a later
point.
--
Perre
Sorry my site is only in Swedish as of now
www.kostforum.se
 

Re:Hyperlink in RichEdit

Per Elmsäter wrote:
Quote
I have a vague memory of using Hot links in a TRichEdit Control some
time several years ago. However I cannot find any info on this and of
course I've forgotten what I did.

The link is to be situated in a Help about box. Besides info on
version etc. I want to have a URL to my website and a mailto: link to
a support email address. Hence it doesn't have to be in a TRichEdit
at all. I just think that's what I used once upon a time.
A combination of the suggestions from Mark and Remy worked like a charm.
Now If I only could add a subject line to my mailto: command I'd be 100%
done with this part. Cannot find any helpfiles that discuss these matters at
all.
--
Perre
Sorry my site is only in Swedish as of now
www.kostforum.se
 

Re:Hyperlink in RichEdit

"Per Elmsäter" < XXXX@XXXXX.COM >wrote in message
Quote
Now If I only could add a subject line to my mailto: command
I'd be 100% done with this part.
Here you go:
ShellExecute(NULL, "open", "mailto: XXXX@XXXXX.COM ?subject=Test", 0, 0,
SW_SHOWNORMAL);
Do note, however, that not all email readers support parameters to the
mailto protocol, or have limitations on which parameters can be used. If
you want more control over the message, then you should use MAPI or SMTP
instead.
Gambit
 

Re:Hyperlink in RichEdit

Remy Lebeau (TeamB) wrote:
Quote
"Per Elmsäter" < XXXX@XXXXX.COM >wrote in message
news:439729cf$ XXXX@XXXXX.COM ...

>Now If I only could add a subject line to my mailto: command
>I'd be 100% done with this part.

Here you go:

ShellExecute(NULL, "open", "mailto: XXXX@XXXXX.COM ?subject=Test", 0,
0, SW_SHOWNORMAL);

Do note, however, that not all email readers support parameters to the
mailto protocol, or have limitations on which parameters can be used.
If you want more control over the message, then you should use MAPI
or SMTP instead.


Gambit
Much obliged. Sir!
--
Perre
Sorry my site is only in Swedish as of now
www.kostforum.se
 

Re:Hyperlink in RichEdit

Remy Lebeau (TeamB) wrote:
Quote
"Per Elmsäter" < XXXX@XXXXX.COM >wrote in message
news:439729cf$ XXXX@XXXXX.COM ...


>Now If I only could add a subject line to my mailto: command
>I'd be 100% done with this part.


Here you go:

ShellExecute(NULL, "open", "mailto: XXXX@XXXXX.COM ?subject=Test", 0, 0,
SW_SHOWNORMAL);

Do note, however, that not all email readers support parameters to the
mailto protocol, or have limitations on which parameters can be used. If
you want more control over the message, then you should use MAPI or SMTP
instead.
You can even have
mailto: XXXX@XXXXX.COM ?subject=email%20title&body=First%20Line%13%10Second%20Line
which would send an email
to: XXXX@XXXXX.COM
subject: email title
body: first line
second line
--
Mark Jacobs
www.dkcomputing.co.uk
 

Re:Hyperlink in RichEdit

Mark Jacobs wrote:
Quote
You can even have
mailto: XXXX@XXXXX.COM ?subject=email%20title&body=First%20Line%13%10Second%20Line

which would send an email
to: XXXX@XXXXX.COM
subject: email title
body: first line
second line

Sorry, that should have been
mailto: XXXX@XXXXX.COM ?subject=email%20title&body=First%20Line%0d%0aSecond%20Line
Hexadecimal codes!
--
Mark Jacobs
www.dkcomputing.co.uk
 

Re:Hyperlink in RichEdit

Mark Jacobs wrote:
Quote
Mark Jacobs wrote:

>You can even have
>mailto: XXXX@XXXXX.COM ?subject=email%20title&body=First%20Line%13%10Second%20Line
>
>which would send an email
>to: XXXX@XXXXX.COM
>subject: email title
>body: first line
>second line
>
Sorry, that should have been
mailto: XXXX@XXXXX.COM ?subject=email%20title&body=First%20Line%0d%0aSecond%20Line


Hexadecimal codes!
Huh, line breaks do not seem to work with Thunderbird. Does anyone know how to break my
two lines in the body parameter of the mailto: protocol?
--
Mark Jacobs
www.dkcomputing.co.uk
 

Re:Hyperlink in RichEdit

"Mark Jacobs" <www.jacobsm.com/mjmsg.htm?mj@critical>wrote in
message news: XXXX@XXXXX.COM ...
Quote
You can even have

mailto: XXXX@XXXXX.COM ?subject=email%20title&body=First%20Line%13%10Second%20Line
A lot of email programs don't support so many simultaneous parameters to the
mailto protocol. Most of the time, you can only use one parameter at a
time, maybe two. There is no guarantee that all supplied parameters will
actually be supported by the user's email program. Hense my suggestion to
use MAPI or SMTP instead when you want finer control over the message.
Gambit