Page Height and Width using GetPageSize

General TRichView support forum. Please post your questions here
Post Reply
Jasmine
Posts: 2
Joined: Tue Oct 17, 2006 2:29 am

Page Height and Width using GetPageSize

Post by Jasmine »

Hi
I would like to get the height and width of a page so that I could use it in the Report Helper. I found on the previous post on GetPageSize. But the coding was in Delphi.

Code: Select all

var w, h: Integer;

// rvoClientTextWidth must be excluded from RichViewEdit1.Options.

GetPageSize(RVPrint1, w,h);
RichViewEdit1.MaxTextWidth :=
  w-RichViewEdit1.LeftMargin-RichViewEdit1.RightMargin;
RichViewEdit1.Format;


procedure GetPageSize(RVPrint: TRVPrint;
                            var Width, Height: Integer);
var DC: HDC;
    phoX, phoY, phW, phH, lpy, lpx, LM, TM, RM, BM: Integer;
begin
  DC := RV_GetPrinterDC; // from PtblRV unit

  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 := MulDiv(RVPrint.LeftMarginMM,   5*lpx, 127)- phoX;
  TM := MulDiv(RVPrint.TopMarginMM,    5*lpy, 127)- phoY;
  RM := MulDiv(RVPrint.RightMarginMM,  5*lpx, 127)- (phW-(phoX+Width));
  BM := MulDiv(RVPrint.BottomMarginMM, 5*lpy, 127)- (phH-(phoY+Height));

  if LM<0 then LM := 0;
  if TM<0 then TM := 0;
  if RM<0 then RM := 0;
  if BM<0 then BM := 0;

  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;

Could I know how to do the GetPageSize in C++ Builder? Because im having problem trying to figure out how the codes in C++ goes.

Thanks!
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Code: Select all

GetPageSize(RVPrint1, w,h); 
RichViewEdit1->MaxTextWidth = 
  w-RichViewEdit1->LeftMargin-RichViewEdit1->RightMargin; 
RichViewEdit1->Format(); 


void GetPageSize(TRVPrint* RVPrint, int& Width, int& Height)
{

  HDC DC = RV_GetPrinterDC(); // from PtblRV unit 

  Width  = GetDeviceCaps(DC, HORZRES); 
  Height = GetDeviceCaps(DC, VERTRES); 

  int lpy = GetDeviceCaps(DC, LOGPIXELSY); 
  int lpx = GetDeviceCaps(DC, LOGPIXELSX); 

  int phoX = GetDeviceCaps(DC, PHYSICALOFFSETX); 
  int phoY = GetDeviceCaps(DC, PHYSICALOFFSETY); 
  int phW  = GetDeviceCaps(DC, PHYSICALWIDTH); 
  int phH  = GetDeviceCaps(DC, PHYSICALHEIGHT); 

  int LM = MulDiv(RVPrint->LeftMarginMM,   5*lpx, 127)- phoX; 
  int TM = MulDiv(RVPrint->TopMarginMM,    5*lpy, 127)- phoY; 
  int RM = MulDiv(RVPrint->RightMarginMM,  5*lpx, 127)- (phW-(phoX+Width)); 
  int BM = MulDiv(RVPrint->BottomMarginMM, 5*lpy, 127)- (phH-(phoY+Height)); 

  if (LM<0) LM = 0; 
  if (TM<0) TM = 0; 
  if (RM<0) RM = 0; 
  if (BM<0) BM = 0; 

  Width -= LM+RM; 
  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); 
}
Jasmine
Posts: 2
Joined: Tue Oct 17, 2006 2:29 am

Post by Jasmine »

Wow.. it works!

Thanks a lot! :D
Post Reply