![]() |
RichEdit Link öffnen
Hoi,
ich würde gerne in einem Fenster, in dem geschrieben wird, URLs erkennen. Das ist auch nicht schwer, aber wie kann ich bewerkstelligen, dass der Link mit ShellExecute geöffnen wird, wenn ich mit der Maus auf den Link fahre und klicke? MfG: sk0r |
Re: RichEdit Link öffnen
|
Re: RichEdit Link öffnen
Diese Variante habe ich mal im Internet gefunden :
Delphi-Quellcode:
erstellt durch
////////////////////////////////////////////////////////////////////////////////
/// /// 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; ![]() |
Re: RichEdit Link öffnen
Aber wozu sich selbst verbiegen, wenn das Richedit das schon von Haus aus mitbringt? Ich wusste das zugegebenermaßen aber auch nicht, bevor ich den Artikel gelesen habe.
|
Re: RichEdit Link öffnen
Danke, es funktioniert.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:11 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 by Thomas Breitkreuz