DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Minor change to TPrintPreview

 
   Reply to topic    DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
Seb@stieN
Member


Joined: 28 May 2003
Posts: 5

PostPosted: 28/05/03 19:45    Post subject: Minor change to TPrintPreview Reply with quote

For TPrintPreview accept more TCustomRichEdit (ex TwwRichEdit)

Code:

function TPrintPreview.PaintRichText(const Rect: TRect;
  RichEdit: TCustomRichEdit; MaxPages: Integer; pOffset: PInteger): Integer;
var
  Range: TFormatRange;
  MaxLen, OldMap: Integer;
  SaveRect: TRect;
  SaveIndex: Integer;
  TextLenEx: TGetTextLengthEx;
begin
  Result := 0;
  FillChar(Range, SizeOf(TFormatRange), 0);
  Range.hdc := Canvas.Handle;
  Range.hdcTarget := Range.hdc;
  Range.rc.Left := ConvertUnit(Rect.Left, Units, mmTWIPS);
  Range.rc.Top := ConvertUnit(Rect.Top, Units, mmTWIPS);
  Range.rc.Right := ConvertUnit(Rect.Right, Units, mmTWIPS);
  Range.rc.Bottom := ConvertUnit(Rect.Bottom, Units, mmTWIPS);
  Range.rcPage := Range.rc;
  Range.chrg.cpMax := -1;
  if pOffset = nil then
    Range.chrg.cpMin := 0
  else
    Range.chrg.cpMin := pOffset^;
  SaveRect := Range.rc;
  //MaxLen := RichEdit.GetTextLen;
  with TextLenEx do
    begin
      flags    := GTL_DEFAULT;
      codepage := CP_ACP;
    end;
  MaxLen := SendMessage(RichEdit.Handle, EM_GETTEXTLENGTHEX, wParam(@TextLenEx), 0);
  SaveIndex := SaveDC(Range.hdc);
  OldMap := SetMapMode(Range.hdc, MM_TEXT);
  //RichEdit.Perform(EM_FORMATRANGE, 0, 0);
  SendMessage(RichEdit.Handle, EM_FORMATRANGE, 0, 0);
  try
    repeat
      if Result > 0  then
      begin
        RestoreDC(Range.hdc, SaveIndex);
        SetMapMode(Range.hdc, OldMap);
        NewPage;
        Range.hdc := Canvas.Handle;
        Range.hdcTarget := Range.hdc;
        SaveIndex := SaveDC(Range.hdc);
        SetMapMode(Range.hdc, MM_TEXT);
        Range.rc := SaveRect;
      end;
      //Range.chrg.cpMin := RichEdit.Perform(EM_FORMATRANGE, 1, Integer(@Range));
      Range.chrg.cpMin := SendMessage(RichEdit.Handle, EM_FORMATRANGE, 1, Integer(@Range));
      if Range.chrg.cpMin <> -1 then
        Inc(Result);
    until (Range.chrg.cpMin >= MaxLen) or (Range.chrg.cpMin = -1) or
          ((MaxPages > 0) and (Result >= MaxPages));
  finally
    //RichEdit.Perform(EM_FORMATRANGE, 0, 0);
    SendMessage(RichEdit.Handle, EM_FORMATRANGE, 0, 0);
    RestoreDC(Range.hdc, SaveIndex);
    SetMapMode(Range.hdc, OldMap);
    if pOffset <> nil then
      if Range.chrg.cpMin < MaxLen then
        pOffset^ := Range.chrg.cpMin
      else
        pOffset^ := -1;
  end;
end;
Back to top
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 206

PostPosted: 28/05/03 19:53    Post subject: Reply with quote

Thank you very much! Smile

Kambiz
Back to top
View user's profile Send e-mail Visit poster's website
Display posts from previous:   
   Reply to topic    DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB 2.0.6 © 2001, 2002 phpBB Group