MFC: Drawing to a device context, splitting STL containers into pages

Hello,

I'm writing an MFC application that produces printed reports. I do this through MFC's device context mechanism - I provide an implementation of a CScrollView's OnDraw(). All of the data that I draw comes from various STL containers that contain CStrings (a description that is mapped to an int which is a database PK, for example). I have an int offset value which increases as I draw things, so that I progressively draw down the page. The drawing logic works fine.

The problem comes when I want to split a larger report into multiple pages. I have to write code to split the containers into pages, before I do my drawing. This is typically very spaghetti-ish. This is what I've done in the past, but the particularly complex code of my most recent report makes me reconsider this approach.

Is there a better way, perhaps with dummy device contexts? Does MFC itself provide a mechanism for this?

Thanks,
Sternocera
sternoceraAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZoppoCommented:
Hi sternocera,

IMO you can use CDC::StartPage/EndPage to controls this, i.e.:

CMyView::OnDraw( CDC* pDC )
{
 ...
 // loop to print lines
 int nOffset = 0;
 while ( ... )
 {
   // print line and increase offset
   ...

   if ( pDC->IsPrinting() )
   {
    // if new page is required
    if ( nOffset > [maximum offset per page] )
    {
      pDC->EndPage();
      pDC->StartPage();
      nOffset = 0;
    }
  }
 }
}

Hope that helps,

ZOPPO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sternoceraAuthor Commented:
Zoppo,

That's very interesting. I'll look into it, and get back to you,

Regards,
Sternocera
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.