Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Printing without Doc/View Architecture

Posted on 1998-09-14
2
Medium Priority
?
230 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 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

Technology Partners: 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

886 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