Integrating WPTools with Rave

Category

Code Based - General

Question

How do you integrate WPTools with Rave?

Solution

The contents for this article were donated by Frank Postova and his team at SIMSOL.

If you are using WPTools and ReportPrinter Pro and you would like to take advantage of WPTools' advanced RTF features, this can easily be done by integrating WPTools into ReportPrinter Pro. You will need to have the ScreenResMode property of the WPRichEdit set to "rm1440", and not the default of "rmNormal."

Delphi Example:

procedure TForm1.ReportSystem1Print(Sender: TObject);

var
  MF: TMetaFile;
  MFC: TMetaFileCanvas;
  R,RR: TRect;
  I1: integer;
  PaperWidth: double;
  PaperHeight: double;
  MyHDC: THandle;// DBWP1 is the TDBWPRichText
begin
  PaperWidth := DBWP1.Header.PageWidth / 1440.0;
  PaperHeight := DBWP1.Header.PageHeight / 1440.0;
  With Sender as TBaseReport do begin
    MF := TMetafile.Create;
    MyHDC := GetDC(0);
    MF.Height := Trunc(PaperHeight * GetDeviceCaps(MyHdc,LOGPIXELSY));
    MF.Width  := Trunc(PaperWidth * GetDeviceCaps(MyHdc,LOGPIXELSX));
    ReleaseDC(0,MyHDC);
    R.Top := 0;
    R.Left := 0;
    R.Right := MF.Width;
    R.Bottom := MF.Height;
    For I1 := 0 to (DBWP1.CountPages - 1) do begin
      MFC := TMetafileCanvas.Create(MF,0);
      DBWP1.PrintPageOnCanvas(MFC,R,I1,[ppmUseBorders,ppmUseEvents],100);
      MFC.Free;
      RR := CreateRect(0.0,0.0,PaperWidth,PaperHeight);
      StretchDraw(RR,MF);
      If I1 < (DBWP1.CountPages - 1) then begin
        NewPage;
      end; { if }
    end; { for }
  end; { with }
  MF.Free;
end;

C++Builder Example:

//  Converted to C++ from Delphi code contributed by Frank Postova, with
//  input from Sven Lindhardt & Eldon Lewis.
//
//---------------------------------------------------------------------------
void __fastcall TForm1::ReportSystem1Print(TObject *Sender)
{
  TMetafile *MF = new TMetafile;
  TMetafileCanvas *MFC;
  TRect R,RR;
  int i, num_pages;
  double PaperWidth, PaperHeight;
  HDC MyHDC;
  TBaseReport *report;
  TPrintPageMode pm_mode;

  //  Create pointer to RP Pro BaseReport....

  report = dynamic_cast(Sender);

  //  Ensure WPRichText->ScreenResMode is rm1440...
  //  Get PaperWidth and PaperHeight of WPRichText...

  PaperWidth = WPRichText1->Header->PageWidth /1440.0;
  PaperHeight =WPRichText1->Header->PageHeight /1440.0;

  // Calculate pixel Height & Width based on screen resolution...

  MyHDC = GetDC(0);
  MF->Height = PaperHeight * GetDeviceCaps(MyHDC, LOGPIXELSY);
  MF->Width = PaperWidth * GetDeviceCaps(MyHDC, LOGPIXELSX);
  ReleaseDC(0,MyHDC);

  //  Define MetaFile "image" size....

  R.Top = R.Left = 0;
  R.Right = MF->Width;
  R.Bottom = MF->Height;

  //  Set options for PrintPageOnCanvas....

  pm_mode = pm_mode << ppmUseBorders << ppmUseEvents;

  //  Get number of pages in WPRichText document...

  num_pages = WPRichText1->CountPages();

  //  For each page, print to the preview window....

  for (i = 0; i < num_pages; i++) {
    //  Create a new MetaFileCanvas....
    MFC = new TMetafileCanvas(MF,0);
    //  Print to canvas, based on screen resolution
    WPRichText1->PrintPageOnCanvas(MFC,R,i,pm_mode,100);
    //MFC->Ellipse(0,0, 100, 100);
    delete MFC;
    // ---------Create "image" size, based on printer resolution!!!!---------
    RR = Rect(0.0,0.0,PaperWidth*report->XDPI,PaperHeight*report->YDPI);
    //  Stretch "image" based on printer resolution....
    report->StretchDraw(RR,MF);
    //  If new WPRichText page.......
    if (i < (num_pages-1)) {
      report->NewPage();
    }
  }
  delete MF;
}