delphi中获取memo鼠标所在位置的行和列(通过EM_GETRECT消息取得Rect后,自己算一下)
也是看别人写的,但是不容易找到,就转发一篇delphi版本的
function GetLine(X, Y: integer): TPoint;
var
OldFont : HFont;
Hand : THandle;
TM : TTextMetric;
Rect : TRect;
begin
Hand := GetDC(mmotest.Handle);
try
OldFont := SelectObject(Hand, mmotest.Font.Handle);
try
GetTextMetrics(Hand, TM);
mmotest.Perform(EM_GETRECT, 0, longint(@Rect));
Result.Y:= GetScrollPos( mmotest.Handle, SB_VERT ) +
(Y - Rect.Top) div (TM.tmHeight);
Result.X:= (X - Rect.Left) div (TM.tmHeight);
ShowMessage( IntToStr( Result.X ) + ',' + IntToStr( Result.Y ) );
finally
SelectObject(Hand, OldFont);
end;
finally
ReleaseDC(mmotest.Handle, Hand);
end;
end;
procedure TF_Main.mmotestMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
GetLine( x, y );
end;
http://blog.csdn.net/youthon/article/details/5781995