DELPHI控件:delphiRichEdit中实现url计算机二级考试
文章作者 100test 发表时间 2009:04:30 03:54:24
来源 100Test.Com百考试题网
2009年下半年全国计算机等级考试你准备好了没?考计算机等级考试的朋友,2009年下半年全国计算机等级考试时间是2009年9月19日至23日。更多优质资料尽在百考试题论坛 百考试题在线题库
unit Unit1.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,RichEdit,Shellapi.
type
TForm1 = class(TForm)
RichEdit1: TRichEdit.
Button1: TButton.
procedure FormCreate(Sender: TObject).
private
{ Private declarations }
public
{ Public declarations }
procedure Wndproc(var Message : TMessage). override.
end.
var
Form1: TForm1.
implementation
{$R *.dfm}
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.
end.