• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

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
0
sternocera
Asked:
sternocera
1 Solution
 
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
 
sternoceraAuthor Commented:
Zoppo,

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

Regards,
Sternocera
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now