Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Printing multiple pages

Posted on 1998-09-11
Medium Priority
Last Modified: 2011-08-18
I'm using Visual C++ and i need to know how to make my program start the next page and continue when i need it to do so e.g i only want x ammount of stuff printed on each page.
thanx in aDvance.

void CMyView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
      CMyDoc * pDoc = GetDocument();

void CMyView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
      CFont font;
      CMyDoc* pDoc = GetDocument();
      ///print text using 10 font
                CLIP_DEFAULT_PRECIS,                        DEFAULT_QUALITY,DEFAULT_PITCH                      FF_ROMAN,"Times New Roman");

      CFont* pOldFont = (CFont*)pDC->SelectObject(&font);
for(int i=0;i<10;i++)
 ////print my stuff
  if(i == 3)
  end the page and start a next page
  here is where i get the problem
  and need help thanx
      TRACE("HORZSIZE = %d,VERTSIZE = %d\n",
      CRecordView::OnPrint(pDC, pInfo);
Question by:mwebster
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2

Author Comment

ID: 1172569
Edited text of question

Accepted Solution

sunj earned 400 total points
ID: 1172570
Hi mwebster,

  Instead of using

for(int i=0;i<10;i++)
  ////print my stuff
   if(i == 3)

try the following:
1. define variables int nstart, nend, numberOfLinesPerPage
2. add these to your OnPrint()
for(int i=nstart;i<nend;i++) {
  //do printing here

The catch is that you can make use of of pInfo->m_nCurPage to decide which page you are in now and how many lines you want to print for this page.


Author Comment

ID: 1172571
is there a way to dynamically set the number of pages my program is not printing what is on screen but rather what's on file from my database so some data will be greater than some and i don't want to set an arbitary ammount of pages in the OnPrepareDC function
thanx again
Technology Partners: 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!


Author Comment

ID: 1172572
this data is being read in a while loop so when the max number of lines i want to start the next page and continue from there
Thanx aGain

Expert Comment

ID: 1172573
Hi mwebster,

  Can you try this:

1. Set the max page number to be a reasonably large value.
2. In your OnPrint() method, keep track of number of lines that has been printed on the current page. e.g.

OnPrint() {
while(1) {
//print m lines here
numberOfLinesPrinted += m;
if(numberOfLinesPrinted > maxNumberOfLinesPerPage)
let me know if there is any further problem. Thanks.


Author Comment

ID: 1172574
i thought about that but here's the problem
void MyView::OnPrint()
 print my stuff
   i want to end the page here
   and start new page

the loop restarts and prints the same thing on the next page
tHanx aGain

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

722 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