也是看别人写的,但是不容易找到,就转发一篇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;
本文介绍了一个Delphi函数GetLine,该函数用于确定鼠标在文本编辑器中的具体字符位置。通过使用Windows API函数和编辑器属性,此函数能够计算出鼠标指针所在的行和列。

3万+

被折叠的 条评论
为什么被折叠?



