trovatore
asked on
non-CView based printing
I need to do non-WYSIWYG printing from an MFC app at
the document level. I'm running into unbelivable
difficulties. It seems that it should be enough to do
the following:
1) Create a CPrintInfo object
2) Call DoPrintDialog on its CPrintDialog member
3) Get the handle for the printer device context by
calling CPrintDialog::GetPrinterDC (). Attach
that handle to a new CDC object (let pDC be
a pointer to this object)
4) Make a DOCINFO structure and call pDC->StartDoc().
5) Call pDC->StartPage().
6) Output whatever I want via pDC->TextOut() .
7) Call pDC->EndPage() and (eventually) pDC->EndDoc() .
But things keep happening that I don't understand--fonts
change on me, code that used to work stops working after
trivial changes, GetTextExtent() returns inconsistent
values, etc. Is there something obvious I'm
missing? I saw somewhere that StartPage() resets device
attributes; how can I reset them? I tried keeping around
a pointer to one of the views just so I could call
pView->OnPrepareDC() after every call to CDC::StartPage(),
but it didn't seem to help.
the document level. I'm running into unbelivable
difficulties. It seems that it should be enough to do
the following:
1) Create a CPrintInfo object
2) Call DoPrintDialog on its CPrintDialog member
3) Get the handle for the printer device context by
calling CPrintDialog::GetPrinterDC
that handle to a new CDC object (let pDC be
a pointer to this object)
4) Make a DOCINFO structure and call pDC->StartDoc().
5) Call pDC->StartPage().
6) Output whatever I want via pDC->TextOut() .
7) Call pDC->EndPage() and (eventually) pDC->EndDoc() .
But things keep happening that I don't understand--fonts
change on me, code that used to work stops working after
trivial changes, GetTextExtent() returns inconsistent
values, etc. Is there something obvious I'm
missing? I saw somewhere that StartPage() resets device
attributes; how can I reset them? I tried keeping around
a pointer to one of the views just so I could call
pView->OnPrepareDC() after every call to CDC::StartPage(),
but it didn't seem to help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, I got through to Codeguru, but the answer was not terribly
relevant. I finally figured it out by myself. The correct
answer is, "You have to call pDC->SetMapMode() and
pDC->SetViewportOrg() and pDC->SelectObject(CFont*)
after every call to pDC->StartPage()".
relevant. I finally figured it out by myself. The correct
answer is, "You have to call pDC->SetMapMode() and
pDC->SetViewportOrg() and pDC->SelectObject(CFont*)
after every call to pDC->StartPage()".
Sorry, I misunderstood your question because I didn't read it carefully. I did encounter the exactly same problem. I should have provided the correct answer. You may reject my answer and ask the customer service to refund you.
ASKER
the basic ideas?