Solved

Printing from within an ODBC SDI application

Posted on 1998-12-20
3
268 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 66
Find Visual Studio Tools 2 121
Best book to learn C++ 4 87
Coding for the first time 9 62
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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

679 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