Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing without Doc/View Architecture

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

-Brent
0
Comment
Question by:xlr8tn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
snoegler earned 200 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

722 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