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
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.