1

为了描述这个问题,您最好使用以下用例测试我的应用程序:

应用程序:http ://ubuntuone.com/p/nF/

  1. 打开应用程序;
  2. 单击“>”标题按钮;
  3. 再次单击相同的按钮;
  4. 再次单击相同的按钮。

如您所见 - 在第一次扩展中正确检测到 URL,但在任何进一步扩展中都没有。

希望在您的帮助下解决此问题:)

目前,每次展开对话框时我都会发送 WM,但它仍然无法正常工作......

展开/折叠按钮代码片段:

    if (PreviewOpn.Caption = '<') and (Width >= 499) then                          // if form is expanded
  begin
   PreviewOpn.Caption := '>';
   if CheckWin32Version(6,0) then begin
     Constraints.MinWidth := 252; ClientWidth := Round(252 - ((Width - ClientWidth) / 2));
    end else begin
     Constraints.MinWidth := 248; ClientWidth := Round(248 - ((Width - ClientWidth) / 2));
    end;
   PopupActionBar1.Items[1].Enabled := False; PopupActionBar1.Items[1].Checked := False;
   if (PreviewOpn.Caption = '<') and (Width >= 248) then PreviewOpn.Caption := '>';
  end else                                                                      // else if form is collapsed
  begin
   SendMessage(RichEdit1.Handle, EM_SETEVENTMASK, 0, EM_GETEVENTMASK or ENM_LINK);       //|
   SendMessage(RichEdit1.Handle, EM_AUTOURLDETECT, Integer(True), 0);
   PreviewOpn.Caption := '<';
   if CheckWin32Version(6,0) then begin
    Constraints.MinWidth := 252; ClientWidth := Round(510 - ((Width - ClientWidth) / 2));
   end else begin
    Constraints.MinWidth := 248; ClientWidth := Round(499 - ((Width - ClientWidth) / 2));
   end;
   PopupActionBar1.Items[1].Enabled := True; PopupActionBar1.Items[1].Checked := True;
   if (PreviewOpn.Caption = '>') and (Width >= 499) then PreviewOpn.Caption := '<';
   if (FileExists(Edit1.Text)) or (FileExists(Edit2.Text)) or (FileExists(ParamStr(1)))
    then RAWInputBtnClick(TabSet1);
  end;
 vClick(VKPInputBtn);                                                           // calls PopuMenu items enabling triggers
 for n := 0 to RichEdit1.Lines.Count - 1 do if RichEdit1.Width < Canvas.TextWidth(RichEdit1.Lines[n]) then  // enable automatic scroolbar settup
  RichEdit1.ScrollBars := ssBoth;

在表单 OnCreate 事件中:

 SendMessage(RichEdit1.Handle, EM_SETEVENTMASK, 0, EM_GETEVENTMASK or ENM_LINK);       //|
 SendMessage(RichEdit1.Handle, EM_AUTOURLDETECT, Integer(True), 0);                    //|
 RichEdit1.Lines[5] := RichEdit1.Lines[5] + ' ';                                       //| resend message for line to fix update issue

正如http://msdn.microsoft.com/en-us/library/bb787991%28VS.85%29.aspx文档所述,通过文本修改检测 URL,这意味着重新调用检测的唯一方法是发送某种消息添加/删除字符,但是:

按下键盘上的键后立即检测到 URL,并且只检测到 INSIDE 行。可能的修复将非常讨厌,因此我什至不认为为此开发代码 sinpp :) 想法:通过所有可用字符 Lopp,例如,添加 Char(#10) 然后删除 Char(#10)。缺点:想象一下 RichEdit 控件内的大型 RTF 文本会发生什么...

4

1 回答 1

1

您没有正确设置事件掩码,EM_GETEVENTMASK 是一条消息 - 而不是标志。你应该这样设置;

  SendMessage(RichEdit1.Handle, EM_SETEVENTMASK, 0,
      SendMessage(RichEdit1.Handle, EM_GETEVENTMASK, 0, 0) or ENM_LINK);


我不知道您在获得 URL 检测后如何丢失它,但如果上述方法没有帮助,据我所知,没有其他方法可以清除和重新分配文本,或修改 URL如您所见,文本本身。

作为旁注,您正在根据线宽设置两个滚动条,这似乎是错误的,垂直滚动条应该与线宽无关。

作为另一个侧节点,您关于更改表单宽度的测试是错误的。

 if (PreviewOpn.Caption = '<') and (Width >= 499) then
  begin
  ...
  end else
  begin
   if CheckWin32Version(6,0) then begin
    Constraints.MinWidth := 252;
    ClientWidth := Round(510 - ((Width - ClientWidth) / 2));
  ...

在上面,当您的表单展开时,它的宽度约为 510,最小宽度为 252。这意味着可以将表单调整为小于 499 的宽度,然后您的“if”将失败,尽管表单扩大了就不会收缩。忘记标题和宽度,并使用像 FFormExpanded 这样的私有字段标志并将其设置为 true 或 false .. 等等...

于 2010-04-21T22:45:05.287 回答