Weil Weihnachten ist (und es mich selbst interessiert hat ...):
Automatische Zeilenwechsel werden an Zeichen aus WhitespaceChars und aus DelimiterChars durchgeführt. Die Implementierung ist nicht ganz perfekt: Wortweise springen nach Links mit Strg + Pfeiltaste verhält sich nicht ganz Standardkonform, aber ich hatte jetzt nicht mehr Zeit.
Delphi-Quellcode:
// Fehlende Definitionen ergänzen
const
WB_CLASSIFY = 3;
WB_MOVEWORDLEFT = 4;
WB_MOVEWORDRIGHT = 5;
WB_LEFTBREAK = 6;
WB_RIGHTBREAK = 7;
WB_CLASS_WHITESPACE = 0;
WB_CLASS_LINEBREAK = 1;
WB_CLASS_DELIMITER = 2;
WB_CLASS_NORMALCHAR = 3;
WBF_CLASS = $0F;
WBF_ISWHITE = $10;
WBF_BREAKLINE = $20;
WBF_BREAKAFTER = $40;
// Zeichengruppen
const
WhitespaceChars:
set of Char = [#9, #32];
LinebreakChars:
set of Char = [#10, #13];
DelimiterChars:
set of Char = [#9, #32, #13, '
.', '
-'];
function EditWordBreakProc(lpch: LPTSTR; ichCurrent: Integer; cch: Integer;
code: Integer): Integer;
stdcall;
begin
case code
of
WB_CLASSIFY:
if lpch[ichCurrent]
in WhitespaceChars
then
Result := WBF_ISWHITE
or WB_CLASS_WHITESPACE
else if lpch[ichCurrent]
in LinebreakChars
then
Result := WBF_BREAKLINE
or WB_CLASS_DELIMITER
else if lpch[ichCurrent]
in DelimiterChars
then
Result := WBF_BREAKAFTER
or WB_CLASS_DELIMITER
else
Result := WB_CLASS_NORMALCHAR;
WB_ISDELIMITER:
if (lpch[ichCurrent]
in DelimiterChars)
then
Result := 1
else
Result := 0;
WB_LEFT, WB_MOVEWORDLEFT:
begin
Dec(ichCurrent);
while (ichCurrent >= 0)
and (lpch[ichCurrent]
in DelimiterChars)
do
Dec(ichCurrent);
while (ichCurrent >= 0)
and not (lpch[ichCurrent]
in DelimiterChars)
do
Dec(ichCurrent);
Result := ichCurrent + 1;
end;
WB_LEFTBREAK:
begin
Dec(ichCurrent);
while (ichCurrent >= 0)
and not (lpch[ichCurrent]
in DelimiterChars)
do
Dec(ichCurrent);
if ichCurrent < 0
then
ichCurrent := 0;
Result := ichCurrent;
end;
WB_RIGHT, WB_MOVEWORDRIGHT:
begin
while (ichCurrent < cch)
and not (lpch[ichCurrent]
in DelimiterChars)
do
Inc(ichCurrent);
while (ichCurrent < cch)
and (lpch[ichCurrent]
in DelimiterChars)
do
Inc(ichCurrent);
Result := ichCurrent;
end;
WB_RIGHTBREAK:
begin
Inc(ichCurrent);
while (ichCurrent < cch)
and not (lpch[ichCurrent]
in DelimiterChars)
do
Inc(ichCurrent);
Result := ichCurrent;
end;
end;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
// Eigene Zeilenumbruchfunktion aktivieren
SendMessage(RichEdit1.Handle, EM_SETWORDBREAKPROC, 0, Integer(@EditWordBreakProc));
end;
Gib deinem Thread bitte noch einen etwas aussagekräftigeren Titel und mach für die zweite Frage einen neuen auf. Sonst findet das später keiner mehr, der vielleicht mal vor dem gleichen Problem steht. Danke.
"Electricity is actually made up of extremely tiny particles called electrons, that you cannot see with the naked eye unless you have been drinking." (Dave Barry)