Solved

Printing without Doc/View Architecture

Posted on 1998-09-14
2
183 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
Comment Utility
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
Comment Utility
Thanks for your help. I will give it a try.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

771 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

12 Experts available now in Live!

Get 1:1 Help Now