Solved

non-CView based printing

Posted on 1998-08-01
4
245 Views
Last Modified: 2013-11-19
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.
0
Comment
Question by:trovatore
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 150 total points
ID: 1320068
0
 

Author Comment

by:trovatore
ID: 1320069
Codeguru is not responding.  For 150 pts you couldn't summarize
the basic ideas?

0
 

Author Comment

by:trovatore
ID: 1320070
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()".


0
 
LVL 23

Expert Comment

by:chensu
ID: 1320071
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

864 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now