URL highlighting in TRichEdit

{....}  
  
protected  
procedure wndproc(var message: tmessage); override;  
  
{....}  
  
  
uses richedit, shellapi;  
  
{today i want to show how to implement url highlighting and url navigation 
without any third-party components. this functionality is implemented in 
richedit from microsoft (and ms outlook use this feature, for example) and 
only borland's developers didn't publish it for us.}  
  
procedure tform1.formcreate(sender: tobject);  
var  
mask: word;  
begin  
mask := sendmessage(richedit1.handle, em_geteventmask, 0, 0);  
sendmessage(richedit1.handle, em_seteventmask, 0, mask or enm_link);  
sendmessage(richedit1.handle, em_autourldetect, integer(true), 0);  
  
//some text in richedit  
richedit1.text := 'scalabium software'#13#10 +  
' site is located at www.scalabium.com. welcome to our site.';  
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;  
Теги:
URL, highlighting, TRichEdit
Добавлено: 09 Апреля 2018 18:51:22 Добавил: Андрей Ковальчук Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...