Solved

Printing from within an ODBC SDI application

Posted on 1998-12-20
3
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert MFC APP to Win32 APP. 19 133
C++ Code Issue 4 48
Gaming Software 1 38
How to add columns to a RAD Studio FMX grid at design time 1 60
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…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

738 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