Solved

Printing from within an ODBC SDI application

Posted on 1998-12-20
3
258 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SetCurrentDirectory path limit 7 93
C++ get user from AD  (VS6) 7 48
C++ question 3 45
White board coding practice 3 60
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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

771 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

15 Experts available now in Live!

Get 1:1 Help Now