Print Preview

Posted on 2003-02-20
Medium Priority
Last Modified: 2013-11-20
This is my first time creating a SDI project.
I am having trouble in that I am just writing text to the screen.  The text looks great on the screen but the Print preview looks compressed and illegible.

I am following the directions from
Appendix C of Sams Teach Yourself VC++6
So, I must be doing something wrong because it doesn't look so great when I print it.

using Win98

Does anybody see anything wrong?

Thanks for your help.

void CPrintItView::OnDraw(CDC* pDC)
     CPrintItDoc* pDoc = GetDocument();
     // TODO: add draw code for native data here
     int left_margin = 20;
     int y = 15;//starting y position
     int line_offset = 20;
      //Declare a client rectangle
     CRect rcClient;

     if(pDC->IsPrinting())//returns true if printing
     //Find the Print width : Window width ratio
          double dWidthRatio=(double)m_rcPrintRect.Width()/(double)rcClient.Width();
     //Find the Print height : Window Height ration
          double dHeightRatio=(double)m_rcPrintRect.Height()/(double)rcClient.Height();
     //Calculate the device's aspect ratio
          double dAspect=(double)pDC->GetDeviceCaps(ASPECTX)/(double)pDC->GetDeviceCaps(ASPECTY);
     //Find the new relative height
          int nHeight=(int)(rcClient.Height()*dWidthRatio*dAspect);
     //Find the new relative width
          int nWidth=(int)(rcClient.Width()*dHeightRatio*(1.0/dAspect));
     //Set the whole rectangle
          rcClient = m_rcPrintRect;

     //Determine the best fit across or down the page
          if(nHeight > nWidth)
               //Down is best, so adjust the width
               rcClient.BottomRight().x=m_rcPrintRect.TopLeft().x + nWidth;
               //Across is best, so adjust the height
               rcClient.BottomRight().y=m_rcPrintRect.TopLeft().y + nHeight;

     // Draw Text

     pDC->TextOut(left_margin,y,"Line one text");
     pDC->TextOut(left_margin,y,"Line two text");
     pDC->TextOut(left_margin,y++,"Line three text");
     pDC->TextOut(left_margin,y++,"Line four text");
     pDC->TextOut(left_margin,y++,"Line five text");
     pDC->TextOut(left_margin,y++,"Line six text");
     pDC->TextOut(left_margin,y++,"Line seven text");
     pDC->TextOut(left_margin,y++,"Line eight text");
Question by:vpomona
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

jackrabbit22 earned 400 total points
ID: 7996709
First thing: Since you're outputting text, would it be a better solution for you to use CEditView or CRichEditView and their built in printing features?

I assume that you're using MM_TEXT mapping mode, which means that each logical drawing unit (the units used in drawing functions like TextOut, LineTo, etc.) is equal to one pixel on the device you're outputing to.  The problem is that each device (screen vs printer) can have a different # of pixels per inch. (resolution)

For the screen, it's usually close to 100 pixels per inch. (I think it's 96?)  For a printer, it's usually 150, 300 or 600 pixels per inch.  This means that the printer output will be 1.5x, 3x or 6x smaller respectively.


- Read up on and using a different mapping mode.  You'll probably find MM_LOENGLISH or MM_ANISOTROPIC a good solution for your problem.

- For samples, check out the printing articles at
http://www.codeguru.com/printing/index.shtml and

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

800 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