现在我有一个软件用到了StringGrid,但不提供打印功能,我没有源码,我想另外写一个程序得到StringGrid的内容,然后在打印,怎么做!

解决方案 »

  1.   

    其实,我已经可以得到edit和memo中的内容,只要向这两个控件的handle发送wm_gettext消息就可以了,但是同样向stringgrid发送就不行,有没有这方面的高手,请帮帮忙!另外 wwwxuhong(用delphi的) 能说得在具体点吗?
      

  2.   

    好象要用要系统消息传递!
    你去看一下:postmessage函数和sendmessage函数!!!
      

  3.   

    楼主思路不对,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!
      

  4.   

    抱歉写错了一点。
    要构住的是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;
      

  5.   

    d983074(d983074) 兄的思路和我不谋而合了,我昨天才想到应该hook api,但我想到的是hook txtout这个函数,我去试试,星期一结账。