RichEdit功能使用,急啊!(100分)

  • 主题发起人 主题发起人 oheart
  • 开始时间 开始时间
O

oheart

Unregistered / Unconfirmed
GUEST, unregistred user!
能够在鼠标指到特定的内容上时给出相应的Hint提示信息。
如:某一行中内容为“点击‘显示’、‘打开’窗口”,当鼠标移动到‘显示’上时,给出提示信息“测试”。当鼠标移动到‘打开’上时,给出提示信息“测试2”。
如果难于实现,可以再加分。谢谢
EmailTo: wangyonglei@chinabetter.com.cn
 
这个我知道怎么做,但是 显示 和 打开 这两个词必须做成超链接的形式,就是字体是蓝色的和带有下划线的
 
有个控件可能适合你,好像是叫fatmemo.你下了试试看。
 
我们现在必须使用RichEdit来实现,有哪位大哥能够提供一下“超链接”或者
“取得鼠标移动位置行的内容”的相关功能代码,感激不尽!
 
还是我来帮你吧,呵呵,搞这个可花了不少时间
unit uLWLinkRichEdit;
interface
uses SysUtils,Windows,Messages,Controls,ComCtrls,Forms,RichEdit,
Classes,Dialogs,Graphics;
type
TLinkTextClick=procedure (LinkText:string);
TLWLinkRichEdit=class(TCustomRichEdit)
private
FMemStream: TMemoryStream;
function ProtectChange(StartPos, EndPos: Integer): Boolean;
function SaveClipboard(NumObj, NumChars: Integer): Boolean;
protected
procedure CreateWnd;
override;
procedure CNNotify(var Message: TWMNotify);
message CN_NOTIFY;
public
property OnChange;
property OnMouseUp;
property OnMouseMove;
property PopupMenu;
property Font;
property ScrollBars;
property HideSelection;
property ReadOnly;
end;

procedure SetWordsLink_RichEdit(Words: string;RichEdit:TLWLinkRichEdit);
var
proLinkTextClick:TLinkTextClick;
proLinkTextMouseEnter:TLinkTextClick;
IsMouseEnterLinkText:Boolean;
implementation
procedure SetWordsLink_RichEdit(Words: string;RichEdit:TLWLinkRichEdit);
var
cf2:CHARFORMAT2;
StartPos : Integer;
ToEnd : Integer;
FindAt : Integer;
tmpPos : integer;
begin
if trim(Words)='' then
Exit;
if RichEdit=nil then
Exit;
tmpPos:=RichEdit.SelStart;
StartPos := 0;
ToEnd := Length(RichEdit.Text);
repeat
FindAt := RichEdit.FindText(Words, StartPos, ToEnd, []);
StartPos := FindAt+Length(Words);
ToEnd := Length(RichEdit.Text)-StartPos;
RichEdit.SelStart := FindAt;
RichEdit.SelLength := Length(Words);
if FindAt<>-1 then
begin
ZeroMemory(@cf2,sizeof(CHARFORMAT2));
cf2.cbSize
:= sizeof(CHARFORMAT2);
cf2.dwMask := CFM_LINK;
cf2.dwEffects :=
CFE_LINK;
RichEdit.Perform(EM_SETCHARFORMAT,
SCF_SELECTION,integer(@cf2));
end;
until FindAt =-1;
RichEdit.SelStart:=tmpPos;
end;

{ TLWLinkRichEdit }
procedure TLWLinkRichEdit.CNNotify(var Message: TWMNotify);
type
PENLink = ^TENLink;
var tmpPos:integer;
begin
with Messagedo
begin
case NMHdr^.code of
EN_SELCHANGE:
SelectionChange;
EN_REQUESTRESIZE:
RequestSize(PReqSize(NMHdr)^.rc);
EN_SAVECLIPBOARD:
with PENSaveClipboard(NMHdr)^do
if not SaveClipboard(cObjectCount, cch)
then
Result := 1;
EN_PROTECTED:
with PENProtected(NMHdr)^.chrgdo
if not ProtectChange(cpMin, cpMax) then
Result := 1;
// 收到EN_LINK 消息,做出回应
EN_LINK:
begin
//这里会得到鼠标移动到上面的消息
Windows.SetCursor
(Screen.Cursors[crHandPoint]);
if (SelLength<=0) and Assigned(proLinkTextMouseEnter) and (not IsMouseEnterLinkText) then
begin
IsMouseEnterLinkText:=True;
SendMessage(Handle, EM_GETSEL, Longint(@tmpPos), 0);
SendMessage(Handle, EM_EXSETSEL, 0,
Longint(@PEnLink(NMHdr)^.chrg));
proLinkTextMouseEnter(GetSelText);
SendMessage(Handle, EM_SETSEL, tmpPos, tmpPos);
end;
if PEnLink(NMHdr)^.msg = WM_LBUTTONDOWN then
begin
// 设置选择范围
SendMessage(Handle, EM_EXSETSEL, 0,
Longint(@PEnLink(NMHdr)^.chrg));
// 传递给Windows并打开
if Assigned(proLinkTextClick) then
proLinkTextClick(GetSelText);
end;
end;
end;
end;
end;

procedure TLWLinkRichEdit.CreateWnd;
var
Plain, DesignMode, WasModified: Boolean;
begin
WasModified := inherited Modified;
inherited CreateWnd;
if (SysLocale.FarEast) and not (SysLocale.PriLangID = LANG_JAPANESE) then
Font.Charset := GetDefFontCharSet;
// 添加 ENM_LINK,以接收 EN_LINK 消息
SendMessage(Handle, EM_SETEVENTMASK, 0,
ENM_CHANGE or ENM_SELCHANGE or
ENM_REQUESTRESIZE or
ENM_PROTECTED or ENM_LINK);
// or ENM_LINK
// 激活URL检测特性
SendMessage(Handle, EM_AUTOURLDETECT,Ord(False), 0);
SendMessage(Handle, EM_SETBKGNDCOLOR, 0,
ColorToRGB(Color));
if FMemStream <> nil then
begin
Plain := PlainText;
FMemStream.ReadBuffer(DesignMode,sizeof(DesignMode));
PlainText := DesignMode;
try
Lines.LoadFromStream(FMemStream);
FMemStream.Free;
FMemStream := nil;
finally
PlainText := Plain;
end;
end;
Modified := WasModified;
end;

function TLWLinkRichEdit.ProtectChange(StartPos, EndPos: Integer): Boolean;
begin
Result := False;
if Assigned(OnProtectChange) then
OnProtectChange(Self, StartPos, EndPos, Result);
end;

function TLWLinkRichEdit.SaveClipboard(NumObj, NumChars: Integer): Boolean;
begin
Result := True;
if Assigned(OnSaveClipboard) then
OnSaveClipboard(Self, NumObj, NumChars, Result);
end;
 
请顺便帮看看我的问题,谢谢
http://www.delphibbs.com/delphibbs/dispq.asp?lid=3876720
 
OK,谢谢!
 
后退
顶部