Link to home
Start Free TrialLog in
Avatar of vpomona
vpomona

asked on

Print Preview

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


void CPrintItView::OnDraw(CDC* pDC)
{
     CPrintItDoc* pDoc = GetDocument();
     ASSERT_VALID(pDoc);
     // 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;
     GetClientRect(&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;
          }
          else
          {
               //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");
     y+=line_offset;
     pDC->TextOut(left_margin,y,"Line two text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line three text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line four text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line five text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line six text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line seven text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line eight text");
     y+=line_offset;
}
ASKER CERTIFIED SOLUTION
Avatar of jackrabbit22
jackrabbit22

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial