Board index » cppbuilder » How to add a URL

How to add a URL


2004-12-24 12:00:10 PM
cppbuilder69
Hi,
I had posted this earlier also but i think my question was a bit
misunderstood and i my posting it again for better visibility. what i want
is a normal richedit component in which a lot of text is written and some
part of the text are hyperlink. Eg. "i m writing this message on a
newsgroup". Now say suppose i want to create a hyperlink on the word
"newsgroup" which connects me to "http"//www.google.com" (say). How to go
about doing this? So when the user clicks on the word newsgroup, an
Explorer window will open connecting me to the above URL. there may be many
different hyperlinks in the text.
Thanks and Regards,
Vishal
 
 

Re:How to add a URL

Hi Vishal:
Which version?
I think RichEdit component that ships with BCB supports only old rtf
format.
So open .doc or .rtf file directly with ShellExecute() OR go for some 3rd
party component.
Sudesh
"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
Quote
Hi,

I had posted this earlier also but i think my question was a bit
misunderstood and i my posting it again for better visibility. what i want
is a normal richedit component in which a lot of text is written and some
part of the text are hyperlink. Eg. "i m writing this message on a
newsgroup". Now say suppose i want to create a hyperlink on the word
"newsgroup" which connects me to "http"//www.google.com" (say). How to go
about doing this? So when the user clicks on the word newsgroup, an
Explorer window will open connecting me to the above URL. there may be
many
different hyperlinks in the text.

Thanks and Regards,
Vishal


 

Re:How to add a URL

Hi Sudesh,
I m using BCB6
I dont want to open a doc file or an rtf. The Richedit component already
contains some text. I want to insert hyperlink onto some text. So that in my
RichEdit component if the user click on some text (which is hpyperlinked to
some URL) then an exploere window should open with that link.Eg "i m
writing this message on a newsgroup". Now say suppose i want to create a
hyperlink on the word "newsgroup" which connects me to
"www.google.com" (say). How to go about doing this?
Thanks and Regards,
Vishal
"Sudesh" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Vishal:
Which version?
I think RichEdit component that ships with BCB supports only old rtf
format.
So open .doc or .rtf file directly with ShellExecute() OR go for some 3rd
party component.
Sudesh

"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>Hi,
>
>I had posted this earlier also but i think my question was a bit
>misunderstood and i my posting it again for better visibility. what i
want
>is a normal richedit component in which a lot of text is written and
some
>part of the text are hyperlink. Eg. "i m writing this message on a
>newsgroup". Now say suppose i want to create a hyperlink on the word
>"newsgroup" which connects me to "http"//www.google.com" (say). How to
go
>about doing this? So when the user clicks on the word newsgroup, an
>Explorer window will open connecting me to the above URL. there may be
>many
>different hyperlinks in the text.
>
>Thanks and Regards,
>Vishal
>
>




 

{smallsort}

Re:How to add a URL

I do not know about BCB6 RichEdit component but I think only way is to use
some 3rd party ActiveX.
Do you want user to enter text and define hyperlink??
Sudesh
"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Sudesh,

I m using BCB6
I dont want to open a doc file or an rtf. The Richedit component already
contains some text. I want to insert hyperlink onto some text. So that in
my
RichEdit component if the user click on some text (which is hpyperlinked
to
some URL) then an exploere window should open with that link.Eg "i m
writing this message on a newsgroup". Now say suppose i want to create a
hyperlink on the word "newsgroup" which connects me to
"www.google.com" (say). How to go about doing this?

Thanks and Regards,
Vishal
 

Re:How to add a URL

No, the hperlink will already be denfined. When user clicks on the hyperlink
a new browser window will be opened for the URL defined in the hyperlink
"Sudesh" < XXXX@XXXXX.COM >wrote in message
Quote
I do not know about BCB6 RichEdit component but I think only way is to use
some 3rd party ActiveX.
Do you want user to enter text and define hyperlink??
Sudesh

"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
news:41cbcf7b$ XXXX@XXXXX.COM ...
>Hi Sudesh,
>
>I m using BCB6
>I dont want to open a doc file or an rtf. The Richedit component already
>contains some text. I want to insert hyperlink onto some text. So that
in
>my
>RichEdit component if the user click on some text (which is hpyperlinked
>to
>some URL) then an exploere window should open with that link.Eg "i m
>writing this message on a newsgroup". Now say suppose i want to create
a
>hyperlink on the word "newsgroup" which connects me to
>"www.google.com" (say). How to go about doing this?
>
>Thanks and Regards,
>Vishal


 

Re:How to add a URL

Vishal, if you search google groups for "TRichEdit Hyperlinks" there are
some posts.
Remy also mentions a free richedit component.
home.att.net/~robertdunn/TaeRichEditInfo.html
Good Luck!
Sudesh
 

Re:How to add a URL

"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
Quote
what i want is a normal richedit component in which a lot of text
is written and some part of the text are hyperlink.
TRichEdit does not natively support what you are asking for. You will have
to set it up manually:
TWndMethod OldWndProc = ULL;
__fastcall TForm1::TForm1(TComponent *Owner)
{
OldWndProc = RichEdit1->WindowProc;
RichEdit1->WindowProc = RichEditWndProc;
int mask = RichEdit1->Perform(EM_GETEVENTMASK, 0, 0);
RichEdit1->Perform(EM_SETEVENTMASK, 0, mask | ENM_LINK);
}
void __fastcall TForm1::RichEditWndProc(TMessage &Message)
{
if( Message.Msg == CN_NOTIFY )
{
LPNMHDR pnmh = reinterpret_cast<LPNMHDR>(Message.LParam);
if( pnmh->code == EN_LINK )
{
ENLINK *enl = reinterpret_cast<ENLINK*>(Message.LParam);
if( enl->msg == WM_LBUTTONUP )
{
AnsiString Buffer;
Buffer.SetLength(enl->chrg.cpMax - enl->chrg.cpMin);
TEXTRANGE Range = {0};
Range.chrg = enl->chrg;
Range.lpstrText = Buffer.c_str();
int length = RichEdit1->Perform(EM_GETTEXTRANGE, 0,
reinterpret_cast<int>(&Range));
Buffer.SetLength(length);
ShellExecute(NULL, "open", Buffer.c_str(), NULL, NULL,
SW_SHOWNORMAL);
Message.Result = 1;
return;
}
}
}
OldWndProc(Message);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
CHARRANGE OldRange = {0};
RichEdit1->Perform(EM_EXGETSEL, 0,
reinterpret_cast<int>(&OldRange));
try
{
int index = RichEdit1->Lines->Add("I'm writing this message on a
newsgroup.");
CHARRANGE NewRange = {0};
NewRange.cpMin = (RichEdit1->Perform(EM_LINEINDEX, index, 0) +
30);
NewRange.cpMax = (NewRange.cpMin + 9);
RichEdit1->Perform(EM_EXSETSEL, 0,
reinterpret_cast<int>(&NewRange));
CHARFORMAT2 CharFormat = {sizeof(CHARFORMAT2), 0};
CharFormat.dwMask = (CFM_UNDERLINE | CFM_COLOR | CFM_LINK);
CharFormat.dwEffects = (CFE_UNDERLINE | CFE_LINK);
CharFormat.crTextColor =
static_cast<COLORREF>(ColorToRGB(clBlue));
RichEdit1->Perform(EM_SETCHARFORMAT, SCF_SELECTION,
reinterpret_cast<int>(&CharFormat));
}
__finally {
RichEdit1->Perform(EM_EXSETSEL, 0,
reinterpret_cast<int>(&OldRange));
}
}
Gambit
 

Re:How to add a URL

Hi Gambit,
I tried using ur code but I faced a followig errors:
[C++ Error] Unit1.cpp(38): E2015 Ambiguity between 'TEXTRANGEA' and
'Richedit::TEXTRANGEA'
[C++ Error] Unit1.cpp(70): E2015 Ambiguity between 'CHARFORMAT2A' and
'Richedit::CHARFORMAT2A'
[C++ Error] Unit1.cpp(70): E2131 Objects of type 'CHARFORMAT2A' cannot be
initialized with { }
[C++ Error] Unit1.cpp(70): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(70): E2139 Declaration missing ;
[C++ Warning] Unit1.cpp(70): W8004 'CharFormat' is assigned a value that is
never used
[C++ Error] Unit1.cpp(70): E2252 'catch' expected
[C++ Error] Unit1.cpp(71): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(72): E2238 Multiple declaration for 'CharFormat'
[C++ Error] Unit1.cpp(71): E2344 Earlier declaration of 'CharFormat'
[C++ Error] Unit1.cpp(72): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(73): E2238 Multiple declaration for 'CharFormat'
[C++ Error] Unit1.cpp(72): E2344 Earlier declaration of 'CharFormat'
[C++ Error] Unit1.cpp(73): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(74): E2303 Type name expected
[C++ Error] Unit1.cpp(74): E2451 Undefined symbol 'NewRange'
[C++ Error] Unit1.cpp(74): E2293 ) expected
[C++ Error] Unit1.cpp(75): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(76): E2190 Unexpected }
[C++ Error] Unit1.cpp(77): E2040 Declaration terminated incorrectly
[C++ Error] Unit1.cpp(80): E2190 Unexpected }
[C++ Error] Unit1.cpp(80): E2190 Unexpected }
Quote
>>>>>>>>>>>>>>>>>>>My sample code is:
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TWndMethod OldWndProc = NULL;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
OldWndProc = RichEdit1->WindowProc;
RichEdit1->WindowProc = RichEditWndProc;
int mask = RichEdit1->Perform(EM_GETEVENTMASK, 0, 0);
RichEdit1->Perform(EM_SETEVENTMASK, 0, mask | ENM_LINK);
}
void __fastcall TForm1::RichEditWndProc(TMessage &Message)
{
if( Message.Msg == CN_NOTIFY )
{
LPNMHDR pnmh = reinterpret_cast<LPNMHDR>(Message.LParam);
if( pnmh->code == EN_LINK )
{
ENLINK *enl = reinterpret_cast<ENLINK*>(Message.LParam);
if( enl->msg == WM_LBUTTONUP )
{
AnsiString Buffer;
Buffer.SetLength(enl->chrg.cpMax - enl->chrg.cpMin);
TEXTRANGE Range = {0};
Range.chrg = enl->chrg;
Range.lpstrText = Buffer.c_str();
int length = RichEdit1->Perform(EM_GETTEXTRANGE, 0,
reinterpret_cast<int>(&Range));
Buffer.SetLength(length);
ShellExecute(NULL, "open", Buffer.c_str(), NULL, NULL,
SW_SHOWNORMAL);
Message.Result = 1;
return;
}
}
}
OldWndProc(Message);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
CHARRANGE OldRange = {0};
RichEdit1->Perform(EM_EXGETSEL, 0,
reinterpret_cast<int>(&OldRange));
try
{
int index = RichEdit1->Lines->Add("I'm writing this message on a
newsgroup.");
CHARRANGE NewRange = {0};
NewRange.cpMin = (RichEdit1->Perform(EM_LINEINDEX, index, 0) +
30);
NewRange.cpMax = (NewRange.cpMin + 9);
RichEdit1->Perform(EM_EXSETSEL, 0,
reinterpret_cast<int>(&NewRange));
CHARFORMAT2 CharFormat = {sizeof(CHARFORMAT2), 0};
CharFormat.dwMask = (CFM_UNDERLINE | CFM_COLOR | CFM_LINK);
CharFormat.dwEffects = (CFE_UNDERLINE | CFE_LINK);
CharFormat.crTextColor =
static_cast<COLORREF>(ColorToRGB(clBlue));
RichEdit1->Perform(EM_SETCHARFORMAT, SCF_SELECTION,
reinterpret_cast<int>(&CharFormat));
}
__finally {
RichEdit1->Perform(EM_EXSETSEL, 0,
reinterpret_cast<int>(&OldRange));
}
}
Quote
>>>>>>>>>>>>>>>>>>>>>>>>The .h file is:
#ifndef Unit1H
#define Unit1H
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TRichEdit *RichEdit1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall RichEditWndProc(TMessage &Message);
};
extern PACKAGE TForm1 *Form1;
#endif
I was able to remove these messages if i use 'Richedit::TEXTRANGEA' and
'Richedit::CHARFORMAT2A' instead of 'TEXTRANGEA' and 'CHARFORMAT2A'. And if
i write "Richedit::CHARFORMAT2 CharFormat;" instead of "CHARFORMAT2
CharFormat = {sizeof(CHARFORMAT2), 0};"
Can you please help me out.. i am using BCB6 and i think it uses higher
version of richedit and NOT 1.0. these higherversion clain to have
"Recognize and execute URL links. " facility but i was unable to figureout
any examples. Also can you please tell me how to add hyperlink in richedit?
Thanks and Regards,
Vishal
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>what i want is a normal richedit component in which a lot of text
>is written and some part of the text are hyperlink.

TRichEdit does not natively support what you are asking for. You will
have
to set it up manually:

TWndMethod OldWndProc = ULL;

__fastcall TForm1::TForm1(TComponent *Owner)
{
OldWndProc = RichEdit1->WindowProc;
RichEdit1->WindowProc = RichEditWndProc;

int mask = RichEdit1->Perform(EM_GETEVENTMASK, 0, 0);
RichEdit1->Perform(EM_SETEVENTMASK, 0, mask | ENM_LINK);
}

void __fastcall TForm1::RichEditWndProc(TMessage &Message)
{
if( Message.Msg == CN_NOTIFY )
{
LPNMHDR pnmh = reinterpret_cast<LPNMHDR>(Message.LParam);
if( pnmh->code == EN_LINK )
{
ENLINK *enl = reinterpret_cast<ENLINK*>(Message.LParam);
if( enl->msg == WM_LBUTTONUP )
{
AnsiString Buffer;
Buffer.SetLength(enl->chrg.cpMax - enl->chrg.cpMin);

TEXTRANGE Range = {0};
Range.chrg = enl->chrg;
Range.lpstrText = Buffer.c_str();

int length = RichEdit1->Perform(EM_GETTEXTRANGE, 0,
reinterpret_cast<int>(&Range));
Buffer.SetLength(length);

ShellExecute(NULL, "open", Buffer.c_str(), NULL, NULL,
SW_SHOWNORMAL);
Message.Result = 1;
return;
}
}
}

OldWndProc(Message);
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
CHARRANGE OldRange = {0};
RichEdit1->Perform(EM_EXGETSEL, 0,
reinterpret_cast<int>(&OldRange));
try
{
int index = RichEdit1->Lines->Add("I'm writing this message on
a
newsgroup.");

CHARRANGE NewRange = {0};
NewRange.cpMin = (RichEdit1->Perform(EM_LINEINDEX, index, 0) +
30);
NewRange.cpMax = (NewRange.cpMin + 9);
RichEdit1->Perform(EM_EXSETSEL, 0,
reinterpret_cast<int>(&NewRange));

CHARFORMAT2 CharFormat = {sizeof(CHARFORMAT2), 0};
CharFormat.dwMask = (CFM_UNDERLINE | CFM_COLOR | CFM_LINK);
CharFormat.dwEffects = (CFE_UNDERLINE | CFE_LINK);
CharFormat.crTextColor =
static_cast<COLORREF>(ColorToRGB(clBlue));
RichEdit1->Perform(EM_SETCHARFORMAT, SCF_SELECTION,
reinterpret_cast<int>(&CharFormat));
}
__finally {
RichEdit1->Perform(EM_EXSETSEL, 0,
reinterpret_cast<int>(&OldRange));
}
}


Gambit


 

Re:How to add a URL

I also tried the code from the url:
www.bcbjournal.org/free_issue/Including_hot_links_in_TRichEdit.htm.
But i want something more. I want some text (which could be a single word)
be made a hyperlink just like the a normal www.abcd.com thing is made a
hyperlink in the example in the above link. I tried ur example but with
errors (or may be i m doing something stupid) i also tried the example in
the link above and i get hyperlink for anything prefixed by http, www, ftp
etc
"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Gambit,

I tried using ur code but I faced a followig errors:
[C++ Error] Unit1.cpp(38): E2015 Ambiguity between 'TEXTRANGEA' and
'Richedit::TEXTRANGEA'
[C++ Error] Unit1.cpp(70): E2015 Ambiguity between 'CHARFORMAT2A' and
'Richedit::CHARFORMAT2A'
[C++ Error] Unit1.cpp(70): E2131 Objects of type 'CHARFORMAT2A' cannot be
initialized with { }
[C++ Error] Unit1.cpp(70): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(70): E2139 Declaration missing ;
[C++ Warning] Unit1.cpp(70): W8004 'CharFormat' is assigned a value that
is
never used
[C++ Error] Unit1.cpp(70): E2252 'catch' expected
[C++ Error] Unit1.cpp(71): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(72): E2238 Multiple declaration for 'CharFormat'
[C++ Error] Unit1.cpp(71): E2344 Earlier declaration of 'CharFormat'
[C++ Error] Unit1.cpp(72): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(73): E2238 Multiple declaration for 'CharFormat'
[C++ Error] Unit1.cpp(72): E2344 Earlier declaration of 'CharFormat'
[C++ Error] Unit1.cpp(73): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(74): E2303 Type name expected
[C++ Error] Unit1.cpp(74): E2451 Undefined symbol 'NewRange'
[C++ Error] Unit1.cpp(74): E2293 ) expected
[C++ Error] Unit1.cpp(75): E2141 Declaration syntax error
[C++ Error] Unit1.cpp(76): E2190 Unexpected }
[C++ Error] Unit1.cpp(77): E2040 Declaration terminated incorrectly
[C++ Error] Unit1.cpp(80): E2190 Unexpected }
[C++ Error] Unit1.cpp(80): E2190 Unexpected }


>>>>>>>>>>>>>>>>>>>>My sample code is:

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TWndMethod OldWndProc = NULL;

__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
OldWndProc = RichEdit1->WindowProc;
RichEdit1->WindowProc = RichEditWndProc;
int mask = RichEdit1->Perform(EM_GETEVENTMASK, 0, 0);
RichEdit1->Perform(EM_SETEVENTMASK, 0, mask | ENM_LINK);
}
void __fastcall TForm1::RichEditWndProc(TMessage &Message)
{
if( Message.Msg == CN_NOTIFY )
{
LPNMHDR pnmh = reinterpret_cast<LPNMHDR>(Message.LParam);
if( pnmh->code == EN_LINK )
{
ENLINK *enl = reinterpret_cast<ENLINK*>(Message.LParam);
if( enl->msg == WM_LBUTTONUP )
{
AnsiString Buffer;
Buffer.SetLength(enl->chrg.cpMax - enl->chrg.cpMin);

TEXTRANGE Range = {0};
Range.chrg = enl->chrg;
Range.lpstrText = Buffer.c_str();

int length = RichEdit1->Perform(EM_GETTEXTRANGE, 0,
reinterpret_cast<int>(&Range));
Buffer.SetLength(length);

ShellExecute(NULL, "open", Buffer.c_str(), NULL, NULL,
SW_SHOWNORMAL);
Message.Result = 1;
return;
}
}
}

OldWndProc(Message);

}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
CHARRANGE OldRange = {0};
RichEdit1->Perform(EM_EXGETSEL, 0,
reinterpret_cast<int>(&OldRange));
try
{
int index = RichEdit1->Lines->Add("I'm writing this message on
a
newsgroup.");

CHARRANGE NewRange = {0};
NewRange.cpMin = (RichEdit1->Perform(EM_LINEINDEX, index, 0) +
30);
NewRange.cpMax = (NewRange.cpMin + 9);
RichEdit1->Perform(EM_EXSETSEL, 0,
reinterpret_cast<int>(&NewRange));

CHARFORMAT2 CharFormat = {sizeof(CHARFORMAT2), 0};
CharFormat.dwMask = (CFM_UNDERLINE | CFM_COLOR | CFM_LINK);
CharFormat.dwEffects = (CFE_UNDERLINE | CFE_LINK);
CharFormat.crTextColor =
static_cast<COLORREF>(ColorToRGB(clBlue));
RichEdit1->Perform(EM_SETCHARFORMAT, SCF_SELECTION,
reinterpret_cast<int>(&CharFormat));
}
__finally {
RichEdit1->Perform(EM_EXSETSEL, 0,
reinterpret_cast<int>(&OldRange));
}
}

>>>>>>>>>>>>>>>>>>>>>>>>>The .h file is:


#ifndef Unit1H
#define Unit1H
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TRichEdit *RichEdit1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall RichEditWndProc(TMessage &Message);

};
extern PACKAGE TForm1 *Form1;
#endif


I was able to remove these messages if i use 'Richedit::TEXTRANGEA' and
'Richedit::CHARFORMAT2A' instead of 'TEXTRANGEA' and 'CHARFORMAT2A'. And
if
i write "Richedit::CHARFORMAT2 CharFormat;" instead of "CHARFORMAT2
CharFormat = {sizeof(CHARFORMAT2), 0};"
Can you please help me out.. i am using BCB6 and i think it uses higher
version of richedit and NOT 1.0. these higherversion clain to have
"Recognize and execute URL links. " facility but i was unable to figureout
any examples. Also can you please tell me how to add hyperlink in
richedit?

Thanks and Regards,
Vishal



"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
news:41cc9f9d$ XXXX@XXXXX.COM ...
>
>"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in
message
>news: XXXX@XXXXX.COM ...
>
>>what i want is a normal richedit component in which a lot of text
>>is written and some part of the text are hyperlink.
>
>TRichEdit does not natively support what you are asking for. You will
have
>to set it up manually:
>
>TWndMethod OldWndProc = ULL;
>
>__fastcall TForm1::TForm1(TComponent *Owner)
>{
>OldWndProc = RichEdit1->WindowProc;
>RichEdit1->WindowProc = RichEditWndProc;
>
>int mask = RichEdit1->Perform(EM_GETEVENTMASK, 0, 0);
>RichEdit1->Perform(EM_SETEVENTMASK, 0, mask | ENM_LINK);
>}
>
>void __fastcall TForm1::RichEditWndProc(TMessage &Message)
>{
>if( Message.Msg == CN_NOTIFY )
>{
>LPNMHDR pnmh = reinterpret_cast<LPNMHDR>(Message.LParam);
>if( pnmh->code == EN_LINK )
>{
>ENLINK *enl = reinterpret_cast<ENLINK*>(Message.LParam);
>if( enl->msg == WM_LBUTTONUP )
>{
>AnsiString Buffer;
>Buffer.SetLength(enl->chrg.cpMax - enl->chrg.cpMin);
>
>TEXTRANGE Range = {0};
>Range.chrg = enl->chrg;
>Range.lpstrText = Buffer.c_str();
>
>int length = RichEdit1->Perform(EM_GETTEXTRANGE, 0,
>reinterpret_cast<int>(&Range));
>Buffer.SetLength(length);
>
>ShellExecute(NULL, "open", Buffer.c_str(), NULL,
NULL,
>SW_SHOWNORMAL);
>Message.Result = 1;
>return;
>}
>}
>}
>
>OldWndProc(Message);
>}
>
>void __fastcall TForm1::Button1Click(TObject *Sender)
>{
>CHARRANGE OldRange = {0};
>RichEdit1->Perform(EM_EXGETSEL, 0,
>reinterpret_cast<int>(&OldRange));
>try
>{
>int index = RichEdit1->Lines->Add("I'm writing this message
on
a
>newsgroup.");
>
>CHARRANGE NewRange = {0};
>NewRange.cpMin = (RichEdit1->Perform(EM_LINEINDEX, index, 0)
+
>30);
>NewRange.cpMax = (NewRange.cpMin + 9);
>RichEdit1->Perform(EM_EXSETSEL, 0,
>reinterpret_cast<int>(&NewRange));
>
>CHARFORMAT2 CharFormat = {sizeof(CHARFORMAT2), 0};
>CharFormat.dwMask = (CFM_UNDERLINE | CFM_COLOR | CFM_LINK);
>CharFormat.dwEffects = (CFE_UNDERLINE | CFE_LINK);
>CharFormat.crTextColor =
>static_cast<COLORREF>(ColorToRGB(clBlue));
>RichEdit1->Perform(EM_SETCHARFORMAT, SCF_SELECTION,
>reinterpret_cast<int>(&CharFormat));
>}
>__finally {
>RichEdit1->Perform(EM_EXSETSEL, 0,
>reinterpret_cast<int>(&OldRange));
>}
>}
>
>
>Gambit
>
>


 

Re:How to add a URL

"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
Quote
I tried using ur code but I faced a followig errors:
Prefix "::" to the items that are causing the ambiquity errors:
::TEXTRANGE Range = {0};
::CHARFORMAT2 CharFormat = {sizeof(CHARFORMAT2), 0};
Quote
I was able to remove these messages if i use 'Richedit::TEXTRANGEA' and
'Richedit::CHARFORMAT2A' instead of 'TEXTRANGEA' and 'CHARFORMAT2A'.
Use the API versions instead of the VCL ones, since the API messages are
being used directly.
Quote
i am using BCB6 and i think it uses higher version of richedit and NOT
1.0.
No, it still uses 1.0. The OS, on the other hand, probably implements a
higher version that 1.0 is mapped to internally.
Quote
these higherversion clain to have "Recognize and execute URL links. "
facility but i was unable to figureout any examples.
Higher versions do have the ability to auto-detect URLs, via the
EM_AUTOURLDETECT message (but not auto-execute them - you still have to do
that yourself manually via the EN_LINK notification).
However, if you enable the auto-detect, you won't be able to do what you
were originally asking for. In your original post, you said that you want
to "create a hyperlink on the word 'newsgroup' which connects me to
'http//www.google.com'". If you enable auto-detect of URLs, you will not be
able to assign "newsgroup" as your hyperlink text, the text must be a
formatted URL only. Microsoft even says as much:
Note When automatic URL detection is enabled, the rich edit control
removes the CFE_LINK effect from modified text that does not have a URL
format recognized by the control. If your application uses the CFE_LINK
effect to mark other types of text, do not enable automatic URL detection.
Quote
Also can you please tell me how to add hyperlink in richedit?
I already did. That is what my previous message was all about.
Gambit
 

Re:How to add a URL

"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
Quote
I also tried the code from the url:
www.bcbjournal.org/free_issue/Including_hot_links_in_TRichEdit.htm.
That code will not do what you are asking for.
Quote
But i want something more. I want some text (which could be a single
word) be made a hyperlink just like the a normal www.abcd.com thing
is made a hyperlink in the example in the above link.
I already showed you exactly how to do that.
Quote
I tried ur example but with errors (or may be i m doing something stupid)
Then fix the errors.
Quote
i also tried the example in the link above and i get hyperlink for
anything
prefixed by http, www, ftp etc
That is what URL auto-detection does.
Gambit
 

Re:How to add a URL

really sorry for bothering you so much..
I treid ur example also after changins a few things to remove a few errors:
1. i changes "::CHARFORMAT2 CharFormat = {sizeof(CHARFORMAT2), 0};" to
::CHARFORMAT2 CharFormat10};
// initialize the CHARFORMAT2 structure to modify the underline type
::memset(&CharFormat, 0, sizeof(CharFormat));
CharFormat.cbSize = sizeof(CharFormat);
and then i was able to get the usual link look on the word newsgroup. The
cursor also changed to a hand type when it passed over the word "newsgroup".
but after i click on newsgroup the control does not go past the following
check: " if( pnmh->code == EN_LINK )" as both these values were come out
to be different. (1794 and 1803) respectively. These are also the values i
get when i click on any other part of the richedit. I searched on msdn and
they say that
"EN_LINK : A rich edit control sends EN_LINK messages when it receives
various messages, for example, when the user clicks the mouse or when the
mouse pointer is over text that has the CFE_LINK effect. The parent window
of the control receives this notification message through a WM_NOTIFY
message."
I couldnt firgure out whats wrong then. everything else is the same
as u told. Do u have any idea as to wht could be missing.
thanks and regards,
Vishal
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I tried using ur code but I faced a followig errors:

Prefix "::" to the items that are causing the ambiquity errors:

::TEXTRANGE Range = {0};

::CHARFORMAT2 CharFormat = {sizeof(CHARFORMAT2), 0};

>I was able to remove these messages if i use 'Richedit::TEXTRANGEA' and
>'Richedit::CHARFORMAT2A' instead of 'TEXTRANGEA' and 'CHARFORMAT2A'.

Use the API versions instead of the VCL ones, since the API messages are
being used directly.

>i am using BCB6 and i think it uses higher version of richedit and NOT
>1.0.

No, it still uses 1.0. The OS, on the other hand, probably implements a
higher version that 1.0 is mapped to internally.

>these higherversion clain to have "Recognize and execute URL links. "
>facility but i was unable to figureout any examples.

Higher versions do have the ability to auto-detect URLs, via the
EM_AUTOURLDETECT message (but not auto-execute them - you still have to do
that yourself manually via the EN_LINK notification).

However, if you enable the auto-detect, you won't be able to do what you
were originally asking for. In your original post, you said that you want
to "create a hyperlink on the word 'newsgroup' which connects me to
'http//www.google.com'". If you enable auto-detect of URLs, you will not
be
able to assign "newsgroup" as your hyperlink text, the text must be a
formatted URL only. Microsoft even says as much:

Note When automatic URL detection is enabled, the rich edit control
removes the CFE_LINK effect from modified text that does not have a URL
format recognized by the control. If your application uses the CFE_LINK
effect to mark other types of text, do not enable automatic URL detection.

>Also can you please tell me how to add hyperlink in richedit?

I already did. That is what my previous message was all about.


Gambit


 

Re:How to add a URL

"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
Quote
after i click on newsgroup the control does not go past the following
check: " if( pnmh->code == EN_LINK )" as both these values were
come out to be different. (1794 and 1803) respectively.
1794 is EN_SELCHANGE. 1803 is EN_LINK.
Quote
These are also the values i get when i click on any other part of the
richedit.
As well you should, because you are changing the edit caret's position every
time you click on the RichEdit, thus you are changing the point of
selection. So you should get EN_SELCHANGE notifications. But you should
also get EN_LINK notifications whenever you do anything that involves text
that has the CFE_LINK effect assigned.
Quote
I couldnt firgure out whats wrong then. everything else is the same
as u told. Do u have any idea as to wht could be missing.
Please show your actual code.
Gambit
 

Re:How to add a URL

here is the actual code:
//--------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TWndMethod OldWndProc = NULL;
//--------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
OldWndProc = RichEdit1->WindowProc;
RichEdit1->WindowProc = RichEditWndProc;
int mask = RichEdit1->Perform(EM_GETEVENTMASK, 0, 0);
RichEdit1->Perform(EM_SETEVENTMASK, 0, mask | ENM_LINK);
}
//--------------------------------------------------------------------------
void __fastcall TForm1::RichEditWndProc(TMessage &Message)
{
if( Message.Msg == CN_NOTIFY )
{
LPNMHDR pnmh = reinterpret_cast<LPNMHDR>(Message.LParam);
if( pnmh->code == EN_LINK )
{
ENLINK *enl = reinterpret_cast<ENLINK*>(Message.LParam);
if( enl->msg == WM_LBUTTONUP )
{
AnsiString Buffer;
Buffer.SetLength(enl->chrg.cpMax - enl->chrg.cpMin);
::TEXTRANGE Range = {0};
Range.chrg = enl->chrg;
Range.lpstrText = Buffer.c_str();
int length = RichEdit1->Perform(EM_GETTEXTRANGE, 0,
reinterpret_cast<int>(&Range));
Buffer.SetLength(length);
ShellExecute(NULL, "open", Buffer.c_str(), NULL, NULL,
SW_SHOWNORMAL);
Message.Result = 1;
return;
}
}
}
OldWndProc(Message);
}
//--------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
CHARRANGE OldRange = {0};
RichEdit1->Perform(EM_EXGETSEL, 0,
reinterpret_cast<int>(&OldRange));
try
{
int index = RichEdit1->Lines->Add("I'm writing this message on a
newsgroup.");
CHARRANGE NewRange = {0};
NewRange.cpMin = (RichEdit1->Perform(EM_LINEINDEX, index, 0) +
30);
NewRange.cpMax = (NewRange.cpMin + 9);
RichEdit1->Perform(EM_EXSETSEL, 0,
reinterpret_cast<int>(&NewRange));
::CHARFORMAT2 CharFormat; // = {sizeof(CHARFORMAT2), 0}; //
this did not work and was giving error. I searched on net and found another
way to initilize after which i got the usual hyperlink effect on the word
"newsgroup".
// initialize the CHARFORMAT2 structure to modify the underline
type
::memset(&CharFormat, 0, sizeof(CharFormat));
CharFormat.cbSize = sizeof(CharFormat);
CharFormat.dwMask = (CFM_UNDERLINE | CFM_COLOR | CFM_LINK);
CharFormat.dwEffects = (CFE_UNDERLINE | CFE_LINK);
CharFormat.crTextColor =
static_cast<COLORREF>(ColorToRGB(clBlue));
RichEdit1->Perform(EM_SETCHARFORMAT, SCF_SELECTION,
reinterpret_cast<int>(&CharFormat));
}
__finally {
RichEdit1->Perform(EM_EXSETSEL, 0,
reinterpret_cast<int>(&OldRange));
}
}
//--------------------------------------------------------------------------
Thanks and Regards,
Vishal
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Vishal Khandelwal" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>after i click on newsgroup the control does not go past the following
>check: " if( pnmh->code == EN_LINK )" as both these values were
>come out to be different. (1794 and 1803) respectively.

1794 is EN_SELCHANGE. 1803 is EN_LINK.

>These are also the values i get when i click on any other part of the
richedit.

As well you should, because you are changing the edit caret's position
every
time you click on the RichEdit, thus you are changing the point of
selection. So you should get EN_SELCHANGE notifications. But you should
also get EN_LINK notifications whenever you do anything that involves text
that has the CFE_LINK effect assigned.

>I couldnt firgure out whats wrong then. everything else is the same
>as u told. Do u have any idea as to wht could be missing.

Please show your actual code.


Gambit