rvico TRichView Reference | Global procedures and functions

RV_GetPrinterDC

Top  Previous  Next

Returns handle compatible with the the current printer object.

Unit PtblRV.

Syntax

function RV_GetPrinterDC: HDC;

After using this handle, delete it with DeleteDC.

Alternatively, you can use Printer.Handle.

Example

The procedure below returns size of document area on page, converted to screen pixels. Document area is paper size minus margins.

For conversion, it uses screen resolution (RichViewPixelsPerInch is ignored).

It does not take headers and footers into account.

procedure GetPageSize(RVPrint: TRVPrintvar Width, Height: Integer); 

var

  DC: HDC; 

  phoX, phoY, phW, phH, lpy, lpx, LM, TM, RM, BM: Integer; 

begin 

  DC := RV_GetPrinterDC;

 

  Width := GetDeviceCaps(DC, HORZRES); 

  Height := GetDeviceCaps(DC, VERTRES); 

 

  lpy := GetDeviceCaps(DC, LOGPIXELSY); 

  lpx := GetDeviceCaps(DC, LOGPIXELSX); 

 

  phoX := GetDeviceCaps(DC, PHYSICALOFFSETX); 

  phoY := GetDeviceCaps(DC, PHYSICALOFFSETY); 

  phW := GetDeviceCaps(DC, PHYSICALWIDTH); 

  phH := GetDeviceCaps(DC, PHYSICALHEIGHT); 

 

  LM := RV_UnitsToPixels(RVPrint.Margins.Left,   FUnits, lpx)- phoX;

  TM := RV_UnitsToPixels(RVPrint.Margins.Top,    FUnits, lpy)- phoY; 

  RM := RV_UnitsToPixels(RVPrint.Margins.Right,  FUnits, lpx)- (phW-(phoX+Width)); 

  BM := RV_UnitsToPixels(RVPrint.Margins.Bottom, FUnits, lpy)- (phH-(phoY+Height)); 

 

  if RVPrint.FixMarginsMode=rvfmmAutoCorrect then

  begin

    if LM<0 then

    begin

      inc(RM, LM);

      LM := 0

    end;

    if TM<0 then

    begin

      inc(BM, TM);

      TM := 0

    end;

    if RM<0 then

      RM := 0

    if BM<0 then

      BM := 0

  end;

 

  dec(Width, LM+RM); 

  dec(Height, TM+BM); 

 

  DeleteDC(DC); 

 

  DC := GetDC(0); 

  Width := MulDiv(Width, GetDeviceCaps(DC, LOGPIXELSX), lpx); 

  Height := MulDiv(Height, GetDeviceCaps(DC, LOGPIXELSY), lpy); 

  ReleaseDC(0, DC); 

end;

Example of using (making document width in editor equal to page width, taking difference in resolutions into account):

var w, h: Integer; 

 

// rvoClientTextWidth must be excluded from RichViewEdit1.Options

 

GetPageSize(RVPrint1, w,h); 

RichViewEdit1.MaxTextWidth := w-RichViewEdit1.LeftMargin-RichViewEdit1.RightMargin;

RichViewEdit1.MinTextWidth := RichViewEdit1.MaxTextWidth;

RichViewEdit1.Format;


TRichView © trichview.com