Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Printing Problems

Printing Problems

Scheduled Pinned Locked Moved C / C++ / MFC
databasedata-structuresquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kjessee
    wrote on last edited by
    #1

    When I was stepping thru this code to see why it was not working I found that the pInfo->m_nCurPage was not being updated. Any idea why? I did not over ride OnBeginPrinting() or OnEndPrinting() CMyView is derived from CEditView

    BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
    {
    CString string;
    int index=0; // Location of the page breaks
    int pages=0;
    m_pbIndex.SetAt(pages, index);

    // Get the number of pages to be printed
    GetWindowText(string);
    while(index >= 0)
    {
    	// find the page breaks and store
    	// the location in the array
    	index = string.Find("\\f", index+1);
    	pages++;
    	m\_pbIndex.SetAt(pages, index);
    }
    
    pInfo->SetMinPage(1);
    pInfo->SetMaxPage(pages - 1);
    
    return DoPreparePrinting(pInfo);
    

    }

    void CMyView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
    {
    // The rectangle on my sheet of paper
    m_nPageHeight = pDC->GetDeviceCaps(VERTRES);
    pInfo->m_rectDraw.SetRect(0, 0, pDC->GetDeviceCaps(HORZRES), m_nPageHeight);

    // Adjusted for Margins
    double LeftOffset = 0.6;        // in imperial inches
    double TopOffset = 0.5;
    double RightOffset = 0.5 ;
    double BottomOffset = 0.5 ;
    pInfo->m\_rectDraw.DeflateRect((int)(pDC->GetDeviceCaps(LOGPIXELSX) \* LeftOffset),
    			(int)(pDC->GetDeviceCaps(LOGPIXELSY) \* TopOffset),
    			(int)(pDC->GetDeviceCaps(LOGPIXELSX) \* RightOffset),
    			(int)(pDC->GetDeviceCaps(LOGPIXELSY) \* BottomOffset));
    
    // Adjust for the correct sheet
    pDC->SetViewportOrg(0, (pInfo->m\_nCurPage-1)\*m\_nPageHeight);
    
    // Print the page
    CMyDoc\* pDoc = GetDocument();
    PrintPage(pDoc, pDC, pInfo);
    

    }

    void CMyView::PrintPage(CJulieDoc* pDoc, CDC* pDC, CPrintInfo* pInfo)
    {
    int beg;
    int end;

    CString string;
    GetWindowText(string);
    beg = pbIndex.GetAt(pInfo->m\_nCurPage-1);
    end = pbIndex.GetAt(pInfo->m\_nCurPage);
    string = string.Mid(beg, end);
    pDC->DrawText(string, pInfo->m\_rectDraw, 
    					DT\_EXTERNALLEADING && 
    					DT\_LEFT && 
    					DT\_NOCLIP);
    

    }

    As always, Thank You

    K 1 Reply Last reply
    0
    • K kjessee

      When I was stepping thru this code to see why it was not working I found that the pInfo->m_nCurPage was not being updated. Any idea why? I did not over ride OnBeginPrinting() or OnEndPrinting() CMyView is derived from CEditView

      BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
      {
      CString string;
      int index=0; // Location of the page breaks
      int pages=0;
      m_pbIndex.SetAt(pages, index);

      // Get the number of pages to be printed
      GetWindowText(string);
      while(index >= 0)
      {
      	// find the page breaks and store
      	// the location in the array
      	index = string.Find("\\f", index+1);
      	pages++;
      	m\_pbIndex.SetAt(pages, index);
      }
      
      pInfo->SetMinPage(1);
      pInfo->SetMaxPage(pages - 1);
      
      return DoPreparePrinting(pInfo);
      

      }

      void CMyView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
      {
      // The rectangle on my sheet of paper
      m_nPageHeight = pDC->GetDeviceCaps(VERTRES);
      pInfo->m_rectDraw.SetRect(0, 0, pDC->GetDeviceCaps(HORZRES), m_nPageHeight);

      // Adjusted for Margins
      double LeftOffset = 0.6;        // in imperial inches
      double TopOffset = 0.5;
      double RightOffset = 0.5 ;
      double BottomOffset = 0.5 ;
      pInfo->m\_rectDraw.DeflateRect((int)(pDC->GetDeviceCaps(LOGPIXELSX) \* LeftOffset),
      			(int)(pDC->GetDeviceCaps(LOGPIXELSY) \* TopOffset),
      			(int)(pDC->GetDeviceCaps(LOGPIXELSX) \* RightOffset),
      			(int)(pDC->GetDeviceCaps(LOGPIXELSY) \* BottomOffset));
      
      // Adjust for the correct sheet
      pDC->SetViewportOrg(0, (pInfo->m\_nCurPage-1)\*m\_nPageHeight);
      
      // Print the page
      CMyDoc\* pDoc = GetDocument();
      PrintPage(pDoc, pDC, pInfo);
      

      }

      void CMyView::PrintPage(CJulieDoc* pDoc, CDC* pDC, CPrintInfo* pInfo)
      {
      int beg;
      int end;

      CString string;
      GetWindowText(string);
      beg = pbIndex.GetAt(pInfo->m\_nCurPage-1);
      end = pbIndex.GetAt(pInfo->m\_nCurPage);
      string = string.Mid(beg, end);
      pDC->DrawText(string, pInfo->m\_rectDraw, 
      					DT\_EXTERNALLEADING && 
      					DT\_LEFT && 
      					DT\_NOCLIP);
      

      }

      As always, Thank You

      K Offline
      K Offline
      kjessee
      wrote on last edited by
      #2

      I figured out how to make it work. Stay tuned for my first article. Kevin

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups