AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

RichEdit Link öffnen

Ein Thema von sk0r · begonnen am 11. Jun 2009 · letzter Beitrag vom 11. Jun 2009
 
Benutzerbild von RWarnecke
RWarnecke

Registriert seit: 31. Dez 2004
Ort: Stuttgart
4.408 Beiträge
 
Delphi XE8 Enterprise
 
#3

Re: RichEdit Link öffnen

  Alt 11. Jun 2009, 10:52
Diese Variante habe ich mal im Internet gefunden :
Delphi-Quellcode:
////////////////////////////////////////////////////////////////////////////////
///
/// If the a url under the mouse cursor and when the left mouse button is used,
/// then open the url in the standard browser
///
procedure TMainForm.RichEditMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (TRichEdit(Sender).Cursor = crHandPoint) and (Button = mbLeft) then
    if pos('http://', TRichEdit(Sender).Hint) > 0 then
      ShellExecute(Application.Handle,'open', PChar(TRichEdit(Sender).Hint), nil, nil, 1);
end;
////////////////////////////////////////////////////////////////////////////////
///
/// To determine if there a url under the mouse cursor and show it in the hint
/// of the TRichEdit component
///
procedure TMainForm.RichEditMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  iCharIndex, iLineIndex, iCharOffset, i, j: Integer;
  Pt: TPoint;
  s: string;
begin
  with TRichEdit(Sender) do
  begin
    Pt := Point(X, Y);
    // Get Character Index from word under the cursor
    iCharIndex := Perform(Messages.EM_CHARFROMPOS, 0, Integer(@Pt));
    if iCharIndex < 0 then Exit;
    // Get line Index
    iLineIndex := Perform(EM_EXLINEFROMCHAR, 0, iCharIndex);
    iCharOffset := iCharIndex - Perform(EM_LINEINDEX, iLineIndex, 0);
    if Lines.Count - 1 < iLineIndex then Exit;
    // store the current line in a variable
    s := Lines[iLineIndex];
    if pos('http://', s) > 0 then
    begin
      // Search the beginning of the word
      i := iCharOffset + 1;
      while (i > 0) and (s[i] <> ' ') do Dec(i);
      // Search the end of the word
      j := iCharOffset + 1;
      while (j <= Length(s)) and (s[j] <> ' ') do Inc(j);
      // Display Text under Cursor
      s := Copy(s, i + 1, j - i);
      ShowHint := true;
      Hint := s;
      Cursor := crHandPoint;
    end
    else
    begin
      ShowHint := false;
      Hint := '';
      Cursor := crDefault;
    end;
  end;
end;
erstellt durch Code-Orakel und dem BBCode-Plugin.
Rolf Warnecke
App4Mission
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:07 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz