Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

RichEdit printing customization

Posted on 1998-05-21
4
Medium Priority
?
330 Views
Last Modified: 2013-11-22
Source code sample needed:

Can anyone point me to a sorce code sample which demonstrates how to customize the RichEdit printing to add my own headers and footers to it?

Thanks,
Sanjay
0
Comment
Question by:skanade
  • 2
4 Comments
 

Expert Comment

by:jhunt
ID: 1347245
Why don't you use Quickreport to print your RichEdit. It very flexible and the only limiet is your imagination !

John
0
 
LVL 1

Accepted Solution

by:
ssite earned 400 total points
ID: 1347246
The idea and solution is simple. I hope you have some basic experience in component writing,
In the vcl source directory you'll find a file called comctrls.pas. look for a function :
TCustomRichEdit.Print

This is the one that does the printing.

What I would do is use the PageRect property of the TRichEdit to set it to the area which you want to let the richedit print its normal printing, and then you have some blank space for you.

To print on this blank space, you need to add a simple call to a function or event that passes on the canvas for the printer, and then you can do what you need.

Here's the function. Create a new component derived from TRichEdit, add a new event and a new function called PrintCustom. Use the code from Print and add the call to the event like I did here (in 2 places) :

procedure TCustomRichEdit.Print(const Caption: string);
var
  Range: TFormatRange;
  LastChar, MaxLen, LogX, LogY, OldMap: Integer;
begin
  FillChar(Range, SizeOf(TFormatRange), 0);
  with Printer, Range do
  begin
    Title := Caption;
    BeginDoc;
    hdc := Handle;
    hdcTarget := hdc;
    LogX := GetDeviceCaps(Handle, LOGPIXELSX);
    LogY := GetDeviceCaps(Handle, LOGPIXELSY);
    if IsRectEmpty(PageRect) then
    begin
      rc.right := PageWidth * 1440 div LogX;
      rc.bottom := PageHeight * 1440 div LogY;
    end
    else begin
      rc.left := PageRect.Left * 1440 div LogX;
      rc.top := PageRect.Top * 1440 div LogY;
      rc.right := PageRect.Right * 1440 div LogX;
      rc.bottom := PageRect.Bottom * 1440 div LogY;
    end;
    rcPage := rc;
    LastChar := 0;
    MaxLen := GetTextLen;
    chrg.cpMax := -1;
    // ensure printer DC is in text map mode
    OldMap := SetMapMode(hdc, MM_TEXT);
    SendMessage(Handle, EM_FORMATRANGE, 0, 0);    // flush buffer
    try
      // call you r event here (first page)
      MyPrintEvent(Canvas); // the canvas is Printer.Canvas
      repeat
        chrg.cpMin := LastChar;
        LastChar := SendMessage(Self.Handle, EM_FORMATRANGE, 1, Longint(@Range));
        if (LastChar < MaxLen) and (LastChar <> -1) then
        begin
          NewPage;
          // now for the new page
          MyPrintEvent(Canvas); // the canvas is Printer.Canvas
       end;
      until (LastChar >= MaxLen) or (LastChar = -1);
      EndDoc;
    finally
      SendMessage(Handle, EM_FORMATRANGE, 0, 0);  // flush buffer
      SetMapMode(hdc, OldMap);       // restore previous map mode
    end;
  end;
end;


Hope it helps.

0
 

Author Comment

by:skanade
ID: 1347247
John,

>>Why don't you use Quickreport to print your RichEdit.

Thanks! I thought QuickReport is only useful for databases and not for individual controls. I tried it but it doesn't work and the online help is hopelessly poor and missing for QRRichEdit component altogether. I tried putting the QRRichEdit on a detail band and connecting it to my RichEdit but it doesn't work. I tried it by itself without a band but it doesn't print full. Then I tried AutoStrech and it gives a GPF. Is there any better document somewhere?

Sanjay
0
 

Author Comment

by:skanade
ID: 1347248
ssite,

Thanks! This is exactly what I needed.

Sanjay
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question