楼主思路不对,tstringgrid自己维护了一个TStringSparseList类来管理grid中的字符串。 所以无法用消息来获得tstringgrid的内容。 但是可以从别的角度来解决这个问题--钩子。 用钩子钩住TextRect这个api, 因为stringgrid要显示它的内容就必须通过这个函数, procedure TStringGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); begin if DefaultDrawing then Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+2, Cells[ACol, ARow]); inherited DrawCell(ACol, ARow, ARect, AState); end; 并且会附带arect这个重要的参数,根据它来判断字符串所在的位置。 至于钩子的使用,搜索出来一大堆,这里就不复述了。:)Googluck!
抱歉写错了一点。 要构住的是ExtTextOut这个api canvas.textout不是api,是delphi在canvas下封装的方法 它调用的是 BOOL ExtTextOut( HDC hdc, // handle to DC int X, // x-coordinate of reference point int Y, // y-coordinate of reference point UINT fuOptions, // text-output options CONST RECT *lprc, // optional dimensions LPCTSTR lpString, // string UINT cbCount, // number of characters in string CONST INT *lpDx // array of spacing values ); 附源代码 procedure TCanvas.TextRect(Rect: TRect; X, Y: Integer; const Text: string); var Options: Longint; begin Changing; RequiredState([csHandleValid, csFontValid, csBrushValid]); Options := ETO_CLIPPED or FTextFlags; if Brush.Style <> bsClear then Options := Options or ETO_OPAQUE; if ((FTextFlags and ETO_RTLREADING) <> 0) and (CanvasOrientation = coRightToLeft) then Inc(X, TextWidth(Text) + 1); Windows.ExtTextOut(FHandle, X, Y, Options, @Rect, PChar(Text), Length(Text), nil); Changed; end;
你去看一下:postmessage函数和sendmessage函数!!!
所以无法用消息来获得tstringgrid的内容。
但是可以从别的角度来解决这个问题--钩子。
用钩子钩住TextRect这个api,
因为stringgrid要显示它的内容就必须通过这个函数,
procedure TStringGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState);
begin
if DefaultDrawing then
Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+2, Cells[ACol, ARow]);
inherited DrawCell(ACol, ARow, ARect, AState);
end;
并且会附带arect这个重要的参数,根据它来判断字符串所在的位置。
至于钩子的使用,搜索出来一大堆,这里就不复述了。:)Googluck!
要构住的是ExtTextOut这个api
canvas.textout不是api,是delphi在canvas下封装的方法
它调用的是
BOOL ExtTextOut(
HDC hdc, // handle to DC
int X, // x-coordinate of reference point
int Y, // y-coordinate of reference point
UINT fuOptions, // text-output options
CONST RECT *lprc, // optional dimensions
LPCTSTR lpString, // string
UINT cbCount, // number of characters in string
CONST INT *lpDx // array of spacing values
);
附源代码
procedure TCanvas.TextRect(Rect: TRect; X, Y: Integer; const Text: string);
var
Options: Longint;
begin
Changing;
RequiredState([csHandleValid, csFontValid, csBrushValid]);
Options := ETO_CLIPPED or FTextFlags;
if Brush.Style <> bsClear then
Options := Options or ETO_OPAQUE;
if ((FTextFlags and ETO_RTLREADING) <> 0) and
(CanvasOrientation = coRightToLeft) then Inc(X, TextWidth(Text) + 1);
Windows.ExtTextOut(FHandle, X, Y, Options, @Rect, PChar(Text),
Length(Text), nil);
Changed;
end;