起始行:
用EM_GETFIRSTVISIBLELINE消息即可。
结束行:
Var
r: TRect;
lastvisibleline, lastlineindex: Integer;
Begin
richedit1.perform( EM_GETRECT, 0, longint( @r ));
r.left := r.left+1;
r.top := r.bottom - 2;
lastlineindex := richedit1.perform( EM_CHARFROMPOS, 0,integer(@r.topleft));
lastvisibleline := richedit1.perform( EM_EXLINEFROMCHAR, 0,lastlineindex);
end;
************************
function RE_GetLastVisibleLine ( RichEdit : TRichEdit ): Integer ;
const
EM_EXLINEFROMCHAR = WM_USER + 54 ;
var
r : TRect ;
i : Integer ;
begin
{
The EM_GETRECT message retrieves the formatting rectangle
of an edit control.
}
RichEdit . Perform ( EM_GETRECT , 0 , Longint (@ r ));
r . Left := r . Left + 1 ;
r . Top := r . Bottom - 2 ;
{
The EM_CHARFROMPOS message retrieves information about the character
closest to a specified point in the client area of an edit control
}
i := RichEdit . Perform ( EM_CHARFROMPOS , 0 , Integer (@ r . topleft ));
{
The EM_EXLINEFROMCHAR message determines which
line contains the specified character in a rich edit control
}
Result := RichEdit . Perform ( EM_EXLINEFROMCHAR , 0 , i );
end ;
{
Sending the EM_GETFIRSTVISIBLELINE message to a multi-line edit control
finds out which line is the first line visible.
This is the line that is currently displayed at the top of the control.
}
function RE_GetFirstVisibleLine ( RichEdit : TRichEdit ): Integer ;
begin
Result := RichEdit . Perform ( EM_GETFIRSTVISIBLELINE , 0 , 0 );
end ;
procedure TForm1 . Button1Click ( Sender : TObject );
begin
Caption := Format ( '%d,%d' ,[ RE_GetFirstVisibleLine ( RichEdit1 ), RE_GetLastVisibleLine ( RichEdit1 )]);
end ;