Ver Mensaje Individual
  #2  
Antiguo 20-10-2016
Mendizabal Mendizabal is offline
Miembro
NULL
 
Registrado: sep 2014
Posts: 31
Reputación: 0
Mendizabal Va por buen camino
Finalmente logré solucionarlo

Código Delphi [-]
procedure TDBRichMemo2.WMPaint(var Message: TWMPaint);
var
  lBmp: TBitmap;
  lCanvas: TCanvas;
  lRichEdit: TCustomRichEdit;
  s: string;
  ch: integer;
  Stream: TStringStream;
begin
  if not (csPaintCopy in ControlState) then
  begin
    inherited;
  end
  else
  begin
    lRichEdit := TCustomRichEdit.Create(nil);
    lRichEdit.ParentWindow := Application.Handle;

    TRichEdit(lRichEdit).Color := Color;
    TRichEdit(lRichEdit).BorderStyle := BorderStyle;
    TRichEdit(lRichEdit).BorderWidth := BorderWidth;
    TRichEdit(lRichEdit).Ctl3D := Ctl3D;
    TRichEdit(lRichEdit).Font.Assign(Font);
    TRichEdit(lRichEdit).MaxLength := MaxLength;
    TRichEdit(lRichEdit).PlainText := PlainText;
    TRichEdit(lRichEdit).ScrollBars := ScrollBars;


    Stream := TStringStream.Create(s);
    try
      lRichEdit.Lines.LoadFromStream(Stream);
    finally
      Stream.Free;
    end;

    lBmp := TBitmap.Create;
    lCanvas := TCanvas.Create;
    lBmp.Width := ClientRect.Right - ClientRect.Left;
    lBmp.Height := ClientRect.Bottom - ClientRect.Top;

    lCanvas.Handle := Message.Dc;
    ch := 0;

    lBmp.Canvas.Brush.Color := Color;
    lBmp.Canvas.Brush.Style := bsSolid;
    lBmp.Canvas.FillRect(ClientRect);

    RichEditToCanvas(lRichEdit,lBmp.Canvas,Screen.PixelsPerInch);
    lCanvas.Draw(0,0, lBmp);

    lRichEdit.Free;
    lBmp.free;
    lCanvas.free;
  end;
end;

Saludos.

Perdón, me había dejado la función RicheditToCanvas:

Código Delphi [-]
procedure RicheditToCanvas(aRichEdit: TCustomRichEdit; BMP: TBitmap; var LastChar: Integer);
var
  Range: TFormatRange;
  LogX, LogY: Integer;
  TextLenEx: TGetTextLengthEx;
  MaxLen: LongInt;
begin
  //SendMessage(aRichEdit.Handle, EM_FORMATRANGE, 0, 0);
  LogX := GetDeviceCaps(BMP.Canvas.Handle, LOGPIXELSX);
  LogY := GetDeviceCaps(BMP.Canvas.Handle, LOGPIXELSY);

  FillChar(Range, SizeOf(Range), 0);

  Range.rcPage.Top    := 0;
  Range.rcPage.Left   := 0;
  Range.rcPage.Right  := PixelsToTwips(BMP.Width, LogX);
  Range.rcPage.Bottom := PixelsToTwips(BMP.Height, LogY);

  Range.rc := Range.rcPage;
  Range.chrg.cpMin := LastChar;
  Range.chrg.cpMax := -1;
  Range.hdc := BMP.Canvas.Handle;
  Range.hdcTarget := Range.hdc;

  try
    LastChar := aRichEdit.Perform(EM_FORMATRANGE, 1, Integer(@Range));
    aRichEdit.Perform(EM_DISPLAYBAND, 0, Integer(@Range.rc));

    //MaxLen:= aRichEdit.GetTextLen;
    with TextLenEx do
    begin
      flags:= GTL_DEFAULT;
      codepage:= CP_ACP;
    end;
    MaxLen := aRichEdit.Perform(EM_GETTEXTLENGTHEX, WParam(@TextLenEx), 0);

    if LastChar >= MaxLen then
      LastChar:= -1;
  finally
    Range.hdc := BMP.Canvas.Handle;
    Range.hdcTarget := Range.hdc;
    aRichEdit.Perform(EM_FORMATRANGE, 0, 0);
  end;
end;

Última edición por Mendizabal fecha: 20-10-2016 a las 15:00:52.
Responder Con Cita