Solved

Printing multiple pages

Posted on 1998-09-11
6
208 Views
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();
      pInfo->SetMaxPage(3);
}

void CMyView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
      CFont font;
      
      pDC->SetMapMode(MM_TWIPS);
      CMyDoc* pDoc = GetDocument();
      ///print text using 10 font
      font.CreateFont(-240,0,0,0,700,FALSE,FALSE,0,
                        ANSI_CHARSET,OUT_DEFAULT_PRECIS,
                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
}
      pDC->SelectObject(pOldFont);
      TRACE("LOGPIXELSX = %d,LOGPIXELSY = %d\n",
            pDC->GetDeviceCaps(LOGPIXELSX),
            pDC->GetDeviceCaps(LOGPIXELSY));
      TRACE("HORZSIZE = %d,VERTSIZE = %d\n",
            pDC->GetDeviceCaps(HORZSIZE),
            pDC->GetDeviceCaps(VERTSIZE));
      
      CRecordView::OnPrint(pDC, pInfo);
}
0
Comment
Question by:mwebster
  • 4
  • 2
6 Comments
 

Author Comment

by:mwebster
ID: 1172569
Edited text of question
0
 
LVL 1

Accepted Solution

by:
sunj earned 100 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()
nstart=(pInfo->m_nCurPage-1)*numberOfLinesPerPage
nend=nstart+numberOfLinesPerPage
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.

sunj
0
 

Author Comment

by:mwebster
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:mwebster
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
0
 
LVL 1

Expert Comment

by:sunj
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)
  break;
}
}
 
let me know if there is any further problem. Thanks.

sunj
0
 

Author Comment

by:mwebster
ID: 1172574
i thought about that but here's the problem
void MyView::OnPrint()
{
while(!m_pSet->IsEOF())
{
 print my stuff
 if(maxlines)
  {
   i want to end the page here
   and start new page
  }
 m_pSet->MoveNext();
}

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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now