Solved

OnPrint Does not get called from CFormView

Posted on 2013-01-02
6
749 Views
Last Modified: 2013-01-03
I am working on MDI Application which has all views as CFormView Derived.
On one of view there is graph displayed which needs to be printed.
I overridden all necessary functions like OnBeginPrinting,OnPrint etc.
But these functions did not get called.Please Help
0
Comment
Question by:enthurao
  • 3
  • 2
6 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 38735912
This might give you a hint (it appears when you create the project):
No Print for FormView

If you want the MFC printing support do not use CFormView based classes.
0
 
LVL 33

Accepted Solution

by:
sarabande earned 500 total points
ID: 38736616
the print functions were provided by CView baseclass. so they were available also in class derived from CFormView which is derived from CScrollView which is derived from CView.

However you need to enable printing by overriding YourFormView::OnPreparePrinting(). See below sample code snippet from msdn:

BOOL CExampleView::OnPreparePrinting(CPrintInfo* pInfo)
{
   //The document has 2 pages.
   pInfo->SetMaxPage(2);
   return CView::DoPreparePrinting(pInfo);
}

Open in new window


the CView::DoPreparePrinting would return non-zero while the CView::OnPreparePrinting returns zero (thus disabling further printing calls).

Sara
0
 

Author Closing Comment

by:enthurao
ID: 38739787
Thank you very much it worked
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 33

Expert Comment

by:sarabande
ID: 38739935
you are welcome.

No printing support will be available by CFormView

the meaning of the statement is that CFormView itself neither enables printing by an override of OnPreparePrinting nor has an implementation for the other printing member functions which would bring the formview's layout and data to paper.

Sara
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 38739944
And the final sentance was:
If you want the MFC printing support do not use CFormView based classes.


A rough translation of the no print support is that you have to code it all yourself wheras most other CView based classes can use the same code for display to screen or print to paper.
0
 
LVL 33

Expert Comment

by:sarabande
ID: 38740529
MFC (VS2010) supports printing for

- CEditView
- CHTMLEditView
- COleDocObjectItem

the ColeDocObjectItem is for active-x data. the printing support is only an interface to "callback" functions of the active-x (which you have to provide).

the edit view is not more than an edit field "pushed" to a view and print support only would print plain text.

the html edit view uses the print function of the web browser.

if you enable printing by overriding OnPreparePrinting the implementation  of the CView::OnPrint would call the OnDraw function of your view class virtually (passing a device context for the printing device) such that all drawing you made for the screen also would be made for the printer (see comment of Andy Ainscow). that doesn't work for form views cause the controls would draw themselves rather than been drawn by the parent formview.

in summary, mfc supports only a framework for printing.

Sara
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

Suggested Solutions

Title # Comments Views Activity
How do I send a SOAP request to an endpoint via Microsoft VS C++? 1 75
Visual c++ and text files 7 67
Infragistics Ultragrid 3 107
Visual Studio 2013 and Eclipse Neon 6 35
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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