I am trying to update RichEdit so that it detects the url and turns it on to open it in a browser. Finding a url is easy, I just use the following code from http://www.scalabium.com/faq/dct0146.htm
mask := SendMessage(MNote.Handle, EM_GETEVENTMASK, 0, 0);
SendMessage(MNote.Handle, EM_SETEVENTMASK, 0, mask or ENM_LINK);
SendMessage(MNote.Handle, EM_AUTOURLDETECT, Integer(True), 0);
but the second part does not work for me. They provide the following code to capture the EN_LINK message and process it:
type
TForm1 = class(TForm)
protected
procedure WndProc(var Message: TMessage); override;
end;
...
procedure TForm1.WndProc(var Message: TMessage);
var
p: TENLink;
strURL: string;
begin
if (Message.Msg = WM_NOTIFY) then
begin
if (PNMHDR(Message.LParam).code = EN_LINK) then
begin
p := TENLink(Pointer(TWMNotify(Message).NMHdr)^);
if (p.msg = WM_LBUTTONDOWN) then
begin
SendMessage(RichEdit1.Handle, EM_EXSETSEL, 0, LongInt(@(p.chrg)));
strURL := RichEdit1.SelText;
ShellExecute(Handle, 'open', PChar(strURL), 0, 0, SW_SHOWNORMAL);
end
end
end;
inherited;
end;
When I run the program, the URL is detected, but clicking on it does nothing. Using debug, I found that Message.Msg = WM_NOTIFY is not valid when I click on the URL. Then I tried to override TRichEdit WndProc, but the result is the same. Any suggestions?