線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1744
推到 Plurk!
推到 Facebook!

關於RichEdit自動判斷網址的問題

答題得分者是:danny
mayday741130
一般會員


發表:11
回覆:8
積分:3
註冊:2006-07-22

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-07-24 10:55:16 IP:140.128.xxx.xxx 訂閱
我想問一下,關於RichEdit自動判斷網址的問題

只要打http://www.yahoo.com.tw之類的, 它會自動在畫底線

請問,有人知道怎麼做判斷嗎?

程式該怎麼寫呢??
------
小LO
編輯記錄
mayday741130 重新編輯於 2007-07-24 11:07:07, 註解 無‧
danny
版主


發表:100
回覆:522
積分:595
註冊:2002-03-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-07-24 15:47:23 IP:211.76.xxx.xxx 訂閱
以下程式碼用Delphi 5 測試過可用
<textarea class="delphi" rows="10" cols="60" name="code"> uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; type TForm1 = class(TForm) RichEdit1: TRichEdit; procedure FormCreate(Sender: TObject); private procedure InitRichEditURLDetection(RE : TRichEdit); public { Public declarations } protected procedure WndProc(var Msg: TMessage); override; end; var Form1: TForm1; implementation {$R *.dfm} uses ShellApi, RichEdit; procedure TForm1.WndProc(var Msg: TMessage); var p: TENLink; sURL: string; CE : TRichEdit; begin if (Msg.Msg = WM_NOTIFY) then begin if (PNMHDR(Msg.lParam).code = EN_LINK) then begin p := TENLink(Pointer(TWMNotify(Msg).NMHdr)^); if (p.Msg = WM_LBUTTONDOWN) then begin try CE := TRichEdit(Form1.ActiveControl); SendMessage(CE.Handle, EM_EXSETSEL, 0, Longint(@(p.chrg))); sURL := CE.SelText; ShellExecute(Handle, 'open', PChar(sURL), 0, 0, SW_SHOWNORMAL); except end; end; end; end; inherited; end; procedure TForm1.InitRichEditURLDetection(RE: TRichEdit); var mask: Word; begin mask := SendMessage(RE.Handle, EM_GETEVENTMASK, 0, 0); SendMessage(RE.Handle, EM_SETEVENTMASK, 0, mask or ENM_LINK); SendMessage(RE.Handle, EM_AUTOURLDETECT, Integer(True), 0); end; procedure TForm1.FormCreate(Sender: TObject); var s: string; begin InitRichEditURLDetection(RichEdit1); s:='Great Delphi tutorials and articles at ' 'http://www.delphi.about.com.' #13#10 'About Delphi Programming site!' #13#10 'Send an email to your Guide: mailto:delphi.guide@about.com'; RichEdit1.Text := s; s:= 'http://www.delphi.about.com. ' ' This Rich Edit does not recognize URLs!'; RichEdit2.Text := s end; </textarea> Source: http://delphi.about.com/library/code/ncaa111803a.htm
------
將問題盡快結案也是一種禮貌!
系統時間:2024-05-03 4:56:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!