Solved

Printing from within an ODBC SDI application

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

815 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

10 Experts available now in Live!

Get 1:1 Help Now