- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望 RichEdit 处理超链接,因此我按照以下说明进行操作:http://delphi.about.com/od/vclusing/l/aa111803a.htm
以下是我对代码所做的更改:
interface
type
TProgCorner = class(TForm)
RichEdit2: TRichEdit;
RichEdit1: TRichEdit;
RichEdit3: TRichEdit;
RichEdit4: TRichEdit;
procedure FormCreate(Sender: TObject);
private
procedure InitRichEditURLDetection(RE: TRichEdit);
protected
procedure WndProc(var Msg: TMessage); override;
end;
implementation
{$R *.DFM}
uses
ShellAPI, RichEdit;
const
AURL_ENABLEURL = 1;
AURL_ENABLEEAURLS = 8;
procedure TProgCorner.InitRichEditURLDetection(RE: TRichEdit);
var
mask: LResult;
begin
mask := SendMessage(RE.Handle, EM_GETEVENTMASK, 0, 0);
//In the debugger mask is always 1, for all 4 Richedits.
SendMessage(RE.Handle, EM_SETEVENTMASK, 0, mask or ENM_LINK);
//returns 67108865
SendMessage(RE.Handle, EM_AUTOURLDETECT, AURL_ENABLEURL, 0);
//Returns 0 = success (according to MSDN), but no joy.
//SendMessage(RE.Handle, EM_AUTOURLDETECT, AURL_ENABLEEAURLS, 0);
//When uncommented returns -2147024809
//I don't think the registration works, but don't know how to fix this.
end;
procedure TProgCorner.WndProc(var Msg: TMessage);
var
p: TENLink;
sURL: string;
CE: TRichEdit;
begin
//'normal' messages do get through here, but...
if (Msg.Msg = WM_NOTIFY) then begin
//...the following line is never reached.
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(ProgCorner.ActiveControl);
SendMessage(CE.Handle, EM_EXSETSEL, 0, LPARAM(@(p.chrg)));
sURL:= CE.SelText;
ShellExecute(Handle, 'open', PChar(sURL), 0, 0, SW_SHOWNORMAL);
except
{ignore}
end;
end;
end;
end;
inherited;
end;
procedure TProgCorner.FormCreate(Sender: TObject);
begin
InitRichEditURLDetection(RichEdit1);
InitRichEditURLDetection(RichEdit2);
InitRichEditURLDetection(RichEdit3);
InitRichEditURLDetection(RichEdit4);
//If I set the text here (and not in the object inspector)
//the richedit shows a hyperlink with the 'hand' cursor.
//but still no WM_notify message gets received in WndProc.
RichEdit1.Text:= 'http://www.example.com';
end;
end.
但是,我使用对象检查器嵌入到 RichEditx.Lines
中的超链接显示为纯文本(不是链接),并且单击它们不起作用。
我使用的是在 Windows 7 上以 Win32 模式运行的 Delphi Seattle。
我做错了什么?
更新
使用发布已弃用的组合SendMessage(RE.Handle, EM_AUTOURLDETECT, AURL_ENABLEURL, 0);
并在 中手动设置
我可以让 Richedit 显示超链接和手形光标。RichEditx.Text:= 'http://www.example.com'
>FormCreate
但是 WndProc 仍然没有收到 WM_Notify
消息。
WndProc 确实接收其他消息。
更新2
由于急于简化问题,我忽略了 RichEdit
位于 Panel
之上的事实。面板会接收 WM_Notify
消息,这样它们就不会到达下面的表单。
最佳答案
问题是 WM_Notify 消息永远不会到达主窗体。
相反,它会被 Richedit 的父级拦截(我出于对齐目的而放置在那里的面板)。
我错误地在问题中忽略了这一事实,认为这并不重要。
也就是说,以下内容对我有用。
但是,我强烈支持 Remy 在架构上更健全的方法,遇到此问题的人们应该首先尝试该方法。
在 VCL.ComCtrls 中
TCustomRichEdit = class(TCustomMemo)
private //Why private !?
procedure CNNotify(var Message: TWMNotifyRE); message CN_NOTIFY;
解决方案是插入我们自己的TRichEdit:
uses
...., RichEdit;
type
TRichEdit = class(ComCtrls.TRichEdit)
procedure CNNotify(var Message: TWMNotifyRE); message CN_NOTIFY;
end; //never mind that its ancester is private, it will still work.
TProgCorner = class(TForm)
我将 RichRdits 存储在一个数组中,因此我可以通过它们的 HWnd
查找它们,而不必循环遍历表单的所有子控件。
implementation
function TProgCorner.RichEditByHandle(Handle: HWnd): TRichEdit;
var
i: integer;
begin
//Keep track of the richedits in an array, initialized on creation.
for i:= Low(RichEdits) to High(RichEdits) do begin
if RichEdits[i].Handle = Handle then exit(RichEdits[i]);
end;
Result:= nil;
end;
procedure TRichEdit.CNNotify(var Message: TWMNotifyRE);
var
p: TENLink;
sURL: string;
CE: TRichEdit;
begin
if (Message.NMHdr.code = EN_LINK) then begin
p:= TENLink(Pointer(TWMNotify(Message).NMHdr)^);
if (p.Msg = WM_LBUTTONDOWN) then begin
try
//CE:= TRichEdit(ProgCorner.ActiveControl);
//SendMessage(CE.Handle, EM_EXSETSEL, 0, Longint(@(p.chrg)));
SendMessage(p.nmhdr.hwndFrom, EM_EXSETSEL, 0, Longint(@(p.chrg)));
CE:= ProgCorner.RichEditByHandle(p.nmhdr.hwndFrom);
if assigned(CE) then begin
sURL:= CE.SelText;
ShellExecute(Handle, 'open', PChar(sURL), 0, 0, SW_SHOWNORMAL);
end;
except
{ignore}
end;
end;
end;
inherited;
end;
幸运的是,即使原始消息处理程序被声明为私有(private),消息处理程序的插入仍然有效。
现在可以了。就像一个魅力。
以下是该单元的完整副本,以供将来引用:
unit ProgCorn;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls, Menus, Clipbrd, LifeConst, Tabnotbk, LifeUtil,
MyLinkLabel, RichEdit;
type
TRichEdit = class(ComCtrls.TRichEdit)
procedure CNNotify(var Message: TWMNotifyRE); message CN_NOTIFY;
end;
TProgCorner = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label1: TLabel;
TabbedNotebook1: TTabbedNotebook;
PopupMenu1: TPopupMenu;
Copy1: TMenuItem;
Panel3: TPanel;
Button1: TButton;
RichEdit1: TRichEdit;
RichEdit2: TRichEdit;
RichEdit3: TRichEdit;
RichEdit4: TRichEdit;
Button2: TButton;
procedure Copy1Click(Sender: TObject);
procedure PopupMenu1Popup(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
RichEdits: array[1..4] of TRichEdit;
procedure InitRichEditURLDetection(RE: TRichEdit);
function RichEditByHandle(Handle: HWnd): TRichEdit;
public
{ Public declarations }
end;
var
ProgCorner: TProgCorner;
implementation
{$R *.DFM}
uses
ShellAPI;
const
AURL_ENABLEEAURLS = 8;
AURL_ENABLEURL = 1;
procedure TProgCorner.InitRichEditURLDetection(RE: TRichEdit);
var
mask: NativeInt;
begin
mask := SendMessage(RE.Handle, EM_GETEVENTMASK, 0, 0);
SendMessage(RE.Handle, EM_SETEVENTMASK, 0, mask or ENM_LINK);
SendMessage(RE.Handle, EM_AUTOURLDETECT, {AURL_ENABLEEAURLS} AURL_ENABLEURL, 0);
end;
procedure TProgCorner.FormCreate(Sender: TObject);
begin
ProgCorner:= Self;
InitRichEditURLDetection(RichEdit1);
InitRichEditURLDetection(RichEdit2);
InitRichEditURLDetection(RichEdit3);
InitRichEditURLDetection(RichEdit4);
RichEdits[1]:= RichEdit1;
RichEdits[2]:= RichEdit2;
RichEdits[3]:= RichEdit3;
RichEdits[4]:= RichEdit4;
//WordWarp should be set during runtime only, because
//otherwise the text will not warp, but rather be cut off
//before run time.
RichEdit1.Text:= RichEdit1.Text + ' ';
RichEdit2.Text:= RichEdit2.Text + ' ';
RichEdit3.Text:= RichEdit3.Text + ' ';
RichEdit4.Text:= RichEdit4.Text + ' ';
RichEdit1.WordWrap:= true;
RichEdit2.WordWrap:= true;
RichEdit3.WordWrap:= true;
RichEdit4.WordWrap:= true;
end;
procedure TProgCorner.Copy1Click(Sender: TObject);
var
ActiveRichEdit: TRichEdit;
begin
ActiveRichEdit:= TRichEdit(Self.FindComponent('RichEdit'+
IntToStr(TabbedNotebook1.PageIndex+1)));
with ActiveRichEdit do begin
if SelText <> '' then Clipboard.AsText:= SelText
else ClipBoard.AsText:= Lines.Text;
end; {with}
end;
procedure TProgCorner.PopupMenu1Popup(Sender: TObject);
begin
Copy1.Enabled:= true;
end;
procedure TProgCorner.Button2Click(Sender: TObject);
begin
Application.HelpContext(4);
end;
{ TRichEdit }
function TProgCorner.RichEditByHandle(Handle: HWnd): TRichEdit;
var
i: integer;
begin
for i:= Low(RichEdits) to High(RichEdits) do begin
if RichEdits[i].Handle = Handle then exit(RichEdits[i]);
end;
Result:= nil;
end;
procedure TRichEdit.CNNotify(var Message: TWMNotifyRE);
var
p: TENLink;
sURL: string;
CE: TRichEdit;
begin
//if (Message.Msg = WM_NOTIFY) then begin
if (Message.NMHdr.code = EN_LINK) then begin
p:= TENLink(Pointer(TWMNotify(Message).NMHdr)^);
if (p.Msg = WM_LBUTTONDOWN) then begin
try
//CE:= TRichEdit(ProgCorner.ActiveControl);
//SendMessage(CE.Handle, EM_EXSETSEL, 0, Longint(@(p.chrg)));
SendMessage(p.nmhdr.hwndFrom, EM_EXSETSEL, 0, Longint(@(p.chrg)));
CE:= ProgCorner.RichEditByHandle(p.nmhdr.hwndFrom);
if assigned(CE) then begin
sURL:= CE.SelText;
ShellExecute(Handle, 'open', PChar(sURL), 0, 0, SW_SHOWNORMAL);
end;
except
{ignore}
end;
end;
end;
//end;
inherited;
end;
end.
关于delphi - RichEdit 不处理超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37790845/
我有一个包含源代码的 TRichEdit 控件。我想设置单行的背景颜色。 我知道如何设置文本 颜色,但是否也可以设置背景颜色?我不是在谈论整个控件的整个背景颜色,我只是在谈论如何更改一行。 我真的必须
我正在将文本从delphi TRichedit 控件输出到打印机。有一个背景图像,所以我使用具有此逻辑的 EM_FORMATRANGE ... myrichedit.Perform(EM_FORMAT
我创建一个新应用程序,放置 TRichedit 并将 PlainText 属性设置为 true。然后,我运行该应用程序并将一些富格式文本粘贴到 RichEdit 中。 我希望它显示为纯文本,但它会显示
添加一行后,我需要将 RichEdit 滚动到最后。我有一个单独的形式的 RichEdit,我根本不想获得焦点。我尝试了经常建议的解决方案: RichEdit.Lines.Add(someText);
(如果您能更好地理解和定义我的问题,请有人编辑标题。) 我遇到的问题是 RichEdit 的样式格式“恢复”回默认的“无”又名 [],然后返回到我设置的任何内容,粗体或斜体示例。 问题所在 - 我认为
RichEdit 控件在成为其他控件的父控件时停止绘制文本。 这是一个功能还是一个错误?是否可以使 RichEdit 成为其他控件的父控件? 查看下一个应用: -- Form1.dfm --- obj
我希望 RichEdit 处理超链接,因此我按照以下说明进行操作:http://delphi.about.com/od/vclusing/l/aa111803a.htm 以下是我对代码所做的更改: i
当我使用多个 RichEdit 控件时,我的行为非常奇怪: LoadLibrary("Msftedit.dll"); RichEdit = CreateWindow("RICHEDIT50W", ""
我想向 RichEdit 控件添加彩色文本行。但我面临的问题是颜色变化不仅限于我选择的文本。我所做的是: 获取当前光标位置 -> 插入文本 -> 获取光标位置 -> 选择范围 -> 为其着色 -> 取
我需要你的帮助!所以,我正在创建一个带有语法高亮器的 RichEdit,我是这样做的: SendMessage(hWin, WM_SETREDRAW, false, 0);
有人知道是否有类似 Memo/RichEdit 的东西吗?需求:对行进行编号,从流中加载大文件(超过 5 MB)。 最佳答案 Developer Express有一套广泛的 VCL 组件,其中包括一个
如何在 RichEdit 中将某一特定行加粗? 最佳答案 丰富的编辑控件中的格式设置如下: 选择要应用格式的文本。 将该格式应用于所选内容。 事情是这样的: RichEdit1.SelStart :=
我有一个 Richedit,允许我的用户格式化和查看我的应用程序中显示的错误消息。 我现在需要能够仅将文本(无格式)导出到他们的故障单系统使用的另一个数据库。 我已经尝试了所有我能想到的纯文本组合,但
我以前从来不需要使用 TRichEdit,一直使用 TMemo。 当我添加 TMemo 等文本时,我希望 RichEdit 自动滚动到末尾。看看添加一些数据后的样子: 如您所见,滚动条保留在顶部,但我
我在计算 Richedit (Delphi XE) 中的字符数时遇到问题。对于每一个新行,我都会多得到两个字符,但在文本中它们不存在。 示例:这里有 15 个字符,但由于换行,richedit 给出了
我试图在 RichEdit 中保存然后恢复垂直滚动位置。 存储滚动位置的全局变量: SI: TScrollInfo; 此代码保存滚动位置: FillChar( SI, SizeOf(SI), #0 )
Delphi 中的大多数 TWinControl 后代都有一个重写方法 CreateParams 来定义它的子类,例如:'EDIT'、'COMBOBOX'、'BUTTON'、'RICHEDIT' 等。
如果您在 Richedit 中加载一些文本,然后单击鼠标左键 + 移动鼠标滚轮,文本将放大或缩小,而不会丢失文本大小格式。 是否有一种简单的方法可以通过几行代码来实现此功能(放大/缩小)? 谢谢 射线
我试图在 RichEdit 中保存然后恢复垂直滚动位置。 存储滚动位置的全局变量: SI: TScrollInfo; 此代码保存滚动位置: FillChar( SI, SizeOf(SI), #0 )
我有一个 TRichEdit。当我选择一些文本并单击另一个元素时,所选文本的选择消失。有没有办法保持这个选择,当 TRichEdit 失去它的焦点时?谢谢! 最佳答案 TRichEdit 有一个属性H
我是一名优秀的程序员,十分优秀!