Board index » delphi » Richedit control problem

Richedit control problem

Hi group

I have a problem which is giving me headaches.

How do I divide the contents of a RichEdit control into pages that
will
print separately.

This would be done in a rich edit file by inserting \page at the point
you want to throw a page.  But the \page seems to be stripped out by
the
RichEdit control's translator  when it prints to the printer.

Can anyone out there help?

TIA

john

 

Re:Richedit control problem


This code is from Peter Below on the Delphi forums that might
get you started. Have a look at the EM_FORMATRANGE message in
the help files to figure out how to have it return the character
index that will start each additional page. If I remember
correctly, a 1 will format the text, while a 0 will only measure
it. Unfortunately, the code we developed from this example is
not handy at the moment.

procedure TForm1.Button1Click(Sender: TObject);
var
  r: TRect;
  richedit_outputarea: TRect;
  printresX, printresY: Integer;
  fmtRange: TFormatRange;
begin
  printer.begindoc;
  try
    r:= Rect( 1000 div 13, 1000 div 13,
               Round((Printer.PageWidth-100) / 1.3),
               Round((Printer.Pageheight-100) / 1.3));
    SetMapMode( printer.canvas.handle, MM_ANISOTROPIC );
    SetWindowExtEx(printer.canvas.handle,
                   GetDeviceCaps(printer.canvas.handle,
LOGPIXELSX),
                   GetDeviceCaps(printer.canvas.handle,
LOGPIXELSY),
                   Nil);
    SetViewportExtEx(printer.canvas.handle,
                   Round(GetDeviceCaps(printer.canvas.handle,
LOGPIXELSX) *
1.3),
                   Round(GetDeviceCaps(printer.canvas.handle,
LOGPIXELSY) *
1.3),
                   Nil);

    With Printer.Canvas Do Begin
      printresX := Round(GetDeviceCaps( handle, LOGPIXELSX) /
1.3 );
      printresY := Round(GetDeviceCaps( handle, LOGPIXELSY) /
1.3 );

      // Define a rectangle for the rich edit text. The height
is set to
the
      // maximum. But we need to convert from device units to
twips,
      // 1 twip = 1/1440 inch or 1/20 point.
      richedit_outputarea :=
        Rect(  r.left * 1440 div printresX,
               r.top * 1440 div printresY,
               r.right * 1440 div printresX,
               r.bottom* 1440 div printresY );

      // Tell rich edit to format its text to the printer. First
set
      // up data record for message:
      fmtRange.hDC := Handle;            // printer handle
      fmtRange.hdcTarget := Handle;     // ditto
      fmtRange.rc := richedit_outputarea;
      fmtRange.rcPage :=
        Rect( 0, 0,
              Printer.PageWidth * 14400 div 13 div printresX,
              Printer.PageHeight * 14400 div 13 div printresY );
      fmtRange.chrg.cpMin := 0;
      fmtRange.chrg.cpMax := richedit1.GetTextLen-1;

      // format the text
      richedit1.Perform( EM_FORMATRANGE, 1, Longint(@fmtRange));
      // and print it
      richedit1.Perform( EM_DISPLAYBAND, 0, Longint(
@fmtRange.rc ));

      // Free cached information
      richedit1.Perform( EM_FORMATRANGE, 0, 0);
    End;
  finally
    printer.enddoc;
  end;
end;

--
Don Westbrook

"Ignorance is the mother of adventure" - Hagar The Horrible

John <j...@bigfoot.com> wrote in article
<3742fbd6.461...@news.demon.co.uk>...

Quote
> Hi group

> I have a problem which is giving me headaches.

> How do I divide the contents of a RichEdit control into pages
that
> will
> print separately.

> This would be done in a rich edit file by inserting \page at
the point
> you want to throw a page.  But the \page seems to be stripped
out by
> the
> RichEdit control's translator  when it prints to the printer.

> Can anyone out there help?

> TIA

> john

Other Threads