Solved

Printing without Doc/View Architecture

Posted on 1998-09-14
2
213 Views
Last Modified: 2010-04-02
Anyone have code to implement printing from a dialog-based application?

-Brent
0
Comment
Question by:xlr8tn
2 Comments
 
LVL 6

Accepted Solution

by:
snoegler earned 50 total points
ID: 1172688
This should work:

void CMyDialog::OnPrint()
{
    DOCINFO     theDoc;
    CString     docName;
    int         tx,ty,sdc;

    docName="Document title";

    theDoc.cbSize       =sizeof(DOCINFO);
    theDoc.lpszDocName  =docName;
    theDoc.lpszOutput   =NULL;
    theDoc.lpszDatatype =NULL;
    theDoc.fwType       =NULL;

    CPrintDialog cpd(
          FALSE,
          PD_HIDEPRINTTOFILE|PD_NOWARNING|PD_PAGENUMS|PD_RETURNDC|PD_USEDEVMODECOPIESANDCOLLATE|PD_NOSELECTION,this);
    CDC* cdc;

    cpd.m_pd.nMinPage   =1;
    cpd.m_pd.nMaxPage   =m_nPages; // no. of pages
    cpd.m_pd.nFromPage  =1;
    cpd.m_pd.nToPage    =m_nPages;

    if(cpd.DoModal()==IDCANCEL) return;

    cdc =new CDC();
    cdc->Attach(cpd.m_pd.hDC);
    cdc->StartDoc(&theDoc);
    tx  =cdc->GetDeviceCaps(HORZRES);
    ty  =cdc->GetDeviceCaps(VERTRES);

  // this part (StartPage() ... EndPage()) may be repeated for each page to print
   cdc->StartPage();
   // painting ...
   cdc->EndPage();

    cdc->EndDoc();
    cdc->Detach();
    delete cdc;
}

Using the CPrintDialog (with the flag PD_RETURNDC set), you'll get a handle to a printer
DC in the CPrintDialog::m_pd.hDC. Then call StartDoc(), StartPage(), EndPage(), EndDoc().
Within StartPage() and EndPage() you can paint to the DC, and repeat this section for
each page ...

Hope this helped ...
0
 

Author Comment

by:xlr8tn
ID: 1172689
Thanks for your help. I will give it a try.
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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

685 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