Printing without built-in support (PLEASE HELP)!
Posted on 1998-11-11
I'm fairly new to the wonderful world of MFC. I'm using VC++ 5.0 with an MDI interface. My problem is the application was initially created without Printing support.
What I'm trying to do is print out a simple text style form using the values that are filled out in a bunch of ListCtrl's inside of a FormView. Unfortunately I get an ASSERT whenever I try to place a CString value in my TextOut function. I looked into the debugger and I see something that asks me if I called DoPreparePrinting()?.
Well here is the code I'm trying to use for my printing routine...
CCalDoc* pDoc = static_cast <CCalDoc*> (GetDocument());
CDC * pDC = new CDC;
// create a CPrintDialog object
CPrintDialog dlg(FALSE, PD_ALLPAGES |
// if no device context clean up, bail out
MessageBox("Invalid Printer Device Context...");
// attach the printer DC handle to the CDC object
CFont * pFont;
pFont = pDC->SelectObject(&font);
// print to the printer device context
// m_strTechname is a CString member
// restore the old font
// delete the printer device handle
// clean up memory
I call this function from my Doc class after pressing a "Print Report" menu button. I have tried adding OnPreparePrinting() and returning DoPreparePrinting() but then I receive nothing at all but a "0" on the printed paper. If anyone has any ideas I would GREATLY appreciate it! And any ideas on a beter approach would be nice also, I do have alot of data I need to print out with multiple pages all contained within a FormView and ListCtrls. The m_strTechname is just the very beginning of the report and it's just an editbox. If anyone needs more information please don't hesitate to E-mail me at firstname.lastname@example.org
Thanks alot for all of your help.