Solved

Printing without Doc/View Architecture

Posted on 1998-09-14
2
193 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

939 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

15 Experts available now in Live!

Get 1:1 Help Now