Solved

Printing from within an ODBC SDI application

Posted on 1998-12-20
3
259 Views
Last Modified: 2010-04-02
What is the best way to print a database in Access that I'm using in my ODBC SDI application? I don't have any sample code to do this. I don't want to see the data on the screen in the CView. I'm just using edit boxes to view the different fields of the records, scrolling and searching for a desired record. All works fine. The printing aspect seems a little more frightening.:)) Thanks for any help in this area.
Bruce Pigeon
Quebec Canada
0
Comment
Question by:pigeonbr
  • 2
3 Comments
 
LVL 4

Expert Comment

by:pagladasu
ID: 1180637
You have to access each record at a time and print the individual fields. All this involves a bit of manual coding. Could you tell me how many fields are there(and their data types)?
thanks
pagladasu
0
 
LVL 4

Accepted Solution

by:
pagladasu earned 50 total points
ID: 1180638
Here is a sample that might be of use.
Make sure Print and Print Preview Options are set.
Use classwizard to map the following messages in the View class

//Comment out OnBeginPrinting and OnEndPrinting
#if 0
void CMyAppView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
      // TODO: Add your specialized code here and/or call the base class
      
      //CFormView::OnBeginPrinting(pDC, pInfo);
}

void CMyAppView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
      // TODO: Add your specialized code here and/or call the base class
      
      //CFormView::OnEndPrinting(pDC, pInfo);
}

#endif

void CMyAppView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
      // TODO: Add your specialized code here and/or call the base class
      pDC->SetMapMode(MM_LOENGLISH);      
      //CFormView::OnPrepareDC(pDC, pInfo);
}

BOOL CMyAppView::OnPreparePrinting(CPrintInfo* pInfo)
{
      // TODO: call DoPreparePrinting to invoke the Print dialog box
      return DoPreparePrinting(pInfo);
}

void CMyAppView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
      // TODO: Add your specialized code here and/or call the base class
      CString str;
      CAbsprojDoc *pDoc=(CAbsprojDoc *)m_pDocument;
      pDC->SetMapMode(MM_TWIPS);
      CFont font;
      TEXTMETRIC tm;
      int nHeight;
      font.CreateFont(-180,0,0,0,400, FALSE, FALSE,
               0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
               CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
               DEFAULT_PITCH|FF_MODERN,"Courier New");
      CFont *pOldFont=(CFont *)(pDC->SelectObject(&font));
      pDC->GetTextMetrics(&tm);
      PrintPageHeader(pDC); //for any report header
      CPoint point(36,-1440);
      CString str1="SECTION",str2="DIFF NO.",str3="RANK",str4="COMMENTS";
      str.Format("%-65s%-10s%-8s%s",str1,str2,str3,str4);
      pDC->TextOut(point.x,point.y,str);
      nHeight=tm.tmHeight + tm.tmExternalLeading;
      point.y-=2*nHeight;
      pDC->MoveTo(point.x,point.y);
      CSize sz=pDC->GetTextExtent(str);
      pDC->LineTo(point.x+sz.cx,point.y);
      //assuming that a pointer to the recordset exists
      m_pSet->MoveFirst();
      while(!m_pSet->IsEOF()){
            point.y-=2*nHeight;
            //assume that there are 4 fields and all of type text
            //namely m_question,m_rank,m_grade,m_comment
            //for other datatypes, they must be converted to CString
            str.Format("%-65s%-10s%-8s%s",
                        m-pSet->m_question,
                        m_pSet->m_rank,
                        m_pSet->m_grade,
                        m_pSet->m_comment);
            pDC->TextOut(point.x,point.y,str);
            m_pSet->MoveNext();
      }
      PrintPageFooter(pDC);
      pInfo->m_bContinuePrinting=FALSE;
      pDC->SelectObject(pOldFont);
      //CFormView::OnPrint(pDC, pInfo);
}

//This function was manually added to the view class
void CMyAppView::PrintPageHeader(CDC *pDC){
      CString str;
      CMyAppDoc *pDoc=(CMyAppDoc *)m_pDocument;
      CPoint point(0,0);
      str="Quality System Self Assessment";
      pDC->TextOut(point.x,point.y,str);
      TEXTMETRIC tm;
      pDC->GetTextMetrics(&tm);
      int nHeight=tm.tmHeight + tm.tmExternalLeading;
      point.y -= nHeight;
      pDC->MoveTo(point.x,point.y);
      CSize sz=pDC->GetTextExtent(str);
      pDC->LineTo(point.x+sz.cx,point.y);
}

void CSummary::PrintPageFooter(CDC *pDC){
      CString str;
      CTime tNow;
      tNow=CTime::GetCurrentTime();
      str=tNow.Format("Dated:%A, %B %d, %Y");
      CPoint point(0,-14000);
      pDC->TextOut(point.x,point.y,str);
}


I hope this helps. Thanks and a Merry Christmas and Happy New Year to you.
pagladasu
0
 

Author Comment

by:pigeonbr
ID: 1180639
Hello again! regarding this question, I have tried this approach and everything is fine except that in the print preview( and on printer) I am not controlling the number of lines per page and everything writes to the same page, overlapping. I have found some code on pagination, however unclear, but I will work on it further...and I will be purchasing a book tomorrow "Programming Microsoft Visual C++ Fifth edition which hopefully will assist me in my studies. Thanks for the sample you sent...I have studied it and understand what is going on now. I will grade on your return, since I can only do one think at a time here I believe...I can't add a comment and grade at the same time. Bye for now!
pigeonbr

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

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

21 Experts available now in Live!

Get 1:1 Help Now