Solved

C++Builder: Getting page width and height

Posted on 2001-08-09
4
471 Views
Last Modified: 2008-03-03
Hi,

My boss forced me to do everything the VCL way now, and I had to rewrite a complete printing routine that I wrote using Win32 code. My Win32 code used MM_LOMETRIC as mapping mode, so I could easily specify where I wanted things, and so it would print the same, regardless of the DPI of the printer. With my VCL version I pulled the same trick, but not using VCL functions, since TCanvas doesn't seem to provide a way of setting mapping modes. So I did it this way:

SetMapMode(pCanvas->Handle, MM_LOMETRIC);

TPrinter gives the page width and height nicely, and the help says that VCL automatically starts a new page if you draw text beyond the bounds of the page... but all this doesn't work right anymore (I fear it's cause of my manual setting of the mapping mode). If I draw a line that should be the width of the page, minus a margin on the left and right sides, then I get a line that starts nicely at the margin, but goes on and on as if the page is 2 - 3 times wider than it actually is. And also, if I draw text lower than the page height (umm.. that is... draw below where the page ends), then it just gets chopped off, no new page is started. This leaves me without some important information, the width and height of the page. If I can somehow calculate those, then I'm happy, and I don't need VCL to start a new page for me, I can do it myself. So my question(s) would be (I guess):

- Is there a way to set the mapping mode with VCL functions? (I passed TCanvas to my print function instead of TPrinter, cause I need to use the same function for previewing)
- If there isn't, is there a way I can still get the proper page width and height? (Maybe perform some calculations on the width/height values TPrinter gives me?)

Thanks in advance,



Paul
0
Comment
Question by:mgdPaul
  • 2
4 Comments
 
LVL 3

Expert Comment

by:andysalih
ID: 6370247
hmmm will this do it


#include <iostream>
#include <iomanip>
using namespace std;
//


    int main() {
         /*notes: newer implementations use ios_base
         and not ios. Also they allow using the following
         syntax:
              cout << left;
         to set the alignment to the left/right
         */
         //
         cout.setf(ios::left,ios::adjustfield);
         cout << setw(20) << "Name:";
         cout.setf(ios::right,ios::adjustfield);
         cout << setw(60) << "Occupation:\n";
         //
         /* change fill character from ' ' to '.' */
         //
         cout.fill('.');
         //
         cout.setf(ios::left,ios::adjustfield);
         cout << setw(20) << "*LuckY*";
         cout.setf(ios::right,ios::adjustfield);
         cout << setw(60) << "Student -- Computer Science\n";
         //
         return 0;
}


cheers
Andy
0
 

Author Comment

by:mgdPaul
ID: 6371607
Emm? I don't see how that code relates to printing (as in, on paper) in VCL, sorry.
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 200 total points
ID: 6371760
1. ::SetMapMode(hPrnDC, MM_ANISOTROPIC); //for example

2.
int nPrnWidth = ::GetDeviceCaps(hPrnDC, PHYSICALWIDTH); //Page width in
pixels
int nPrnHeight = ::GetDeviceCaps(hPrnDC, PHYSICALHEIGHT);//Page height in
pixels
int nPrnXDpI = ::GetDeviceCaps(hPrnDC, LOGPIXELSX);//Printer Pixels per Inch
for X axes
int nPrnYDpI = ::GetDeviceCaps(hPrnDC, LOGPIXELSY);//Printer Pixels per Inch
for Y axes

3.Remember, we have got two DCs, hScreenDC and hPrnDC.
And you can use all API for thous DC

4.
Plus you can use TPrinter PageHeight and PageWidth properties that return the width and
height of the page in inches multiplied by the printer's resolution,
respectively. For example, a 300dpi resolution printer using 8"x10" paper would
report a PageWidth of (8 x 300 = 2400) and a PageHeight of (10 x 300 = 3000).


0
 

Author Comment

by:mgdPaul
ID: 6371782
Thanks!

I hope I can get my print function to work properly now, cause I've had problems with it for months now, and different problems every time (and the customer keeps wanting modifications) :(
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

680 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